home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 6 / QRZ Ham Radio Callsign Database - Volume 6.iso / pc / files / dsp / dspkgctr.z / dspkgctr / gcc / c-parse.y < prev    next >
Encoding:
Text File  |  1992-06-08  |  75.7 KB  |  2,932 lines

  1. /* YACC parser for C syntax.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4.    $Id: c-parse.y,v 1.13 92/05/13 22:07:08 pete Exp $
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. /* To whomever it may concern: I have heard that such a thing was once
  24. written by AT&T, but I have never seen it.  */
  25.  
  26. %expect 8
  27.  
  28. /* These are the 8 conflicts you should get in parse.output;
  29.    the state numbers may vary if minor changes in the grammar are made.
  30.  
  31. State 41 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  32. State 92 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  33. State 99 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  34. State 103 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  35. State 119 contains 1 shift/reduce conflict.  (See comment at component_decl.)
  36. State 183 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  37. State 193 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  38. State 199 contains 1 shift/reduce conflict.  (Two ways to recover from error.)
  39. */
  40.  
  41. %{
  42. #include "config.h"
  43. #include "tree.h"
  44. #include "input.h"
  45. #include "c-parse.h"
  46. #include "c-tree.h"
  47.  
  48. #include <stdio.h>
  49. #include <errno.h>
  50.  
  51. #ifndef errno
  52. extern int errno;
  53. #endif
  54.  
  55. void yyerror ();
  56.  
  57. /* Cause the `yydebug' variable to be defined.  */
  58. #define YYDEBUG 1
  59. %}
  60.  
  61. %start program
  62.  
  63. %union {long itype; tree ttype; enum tree_code code; }
  64.  
  65. /* All identifiers that are not reserved words
  66.    and are not declared typedefs in the current block */
  67. %token IDENTIFIER
  68.  
  69. /* All identifiers that are declared typedefs in the current block.
  70.    In some contexts, they are treated just like IDENTIFIER,
  71.    but they can also serve as typespecs in declarations.  */
  72. %token TYPENAME
  73.  
  74. /* Reserved words that specify storage class.
  75.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  76. %token SCSPEC
  77.  
  78. /* Reserved words that specify type.
  79.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  80. %token TYPESPEC
  81.  
  82. /* Reserved words that qualify type: "const" or "volatile".
  83.    yylval contains an IDENTIFIER_NODE which indicates which one.  */
  84. %token TYPE_QUAL
  85.  
  86. /* Character or numeric constants.
  87.    yylval is the node for the constant.  */
  88. %token CONSTANT
  89.  
  90. /* String constants in raw form.
  91.    yylval is a STRING_CST node.  */
  92. %token STRING
  93.  
  94. /* "...", used for functions with variable arglists.  */
  95. %token ELLIPSIS
  96.  
  97. /* the reserved words */
  98. %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
  99. %token BREAK CONTINUE RETURN GOTO ASM TYPEOF ALIGNOF
  100. %token ATTRIBUTE
  101.  
  102. /* Add precedence rules to solve dangling else s/r conflict */
  103. %nonassoc IF
  104. %nonassoc ELSE
  105.  
  106. /* Define the operator tokens and their precedences.
  107.    The value is an integer because, if used, it is the tree code
  108.    to use in the expression made from the operator.  */
  109.  
  110. %right <code> ASSIGN '='
  111. %right <code> '?' ':'
  112. %left <code> OROR
  113. %left <code> ANDAND
  114. %left <code> '|'
  115. %left <code> '^'
  116. %left <code> '&'
  117. %left <code> EQCOMPARE
  118. %left <code> ARITHCOMPARE
  119. %left <code> LSHIFT RSHIFT
  120. %left <code> '+' '-'
  121. %left <code> '*' '/' '%'
  122. %right <code> UNARY PLUSPLUS MINUSMINUS
  123. %left HYPERUNARY
  124. %left <code> POINTSAT '.' '(' '['
  125.  
  126. %type <code> unop
  127.  
  128. %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
  129. %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
  130. %type <ttype> typed_declspecs reserved_declspecs
  131. %type <ttype> typed_typespecs reserved_typespecquals
  132. %type <ttype> declmods typespec typespecqual_reserved
  133. %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
  134. %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
  135. %type <ttype> init initlist maybeasm
  136. %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
  137. %type <ttype> maybe_attribute attribute_list attrib
  138.  
  139. %type <ttype> compstmt
  140.  
  141. %type <ttype> declarator
  142. %type <ttype> notype_declarator after_type_declarator
  143. %type <ttype> parm_declarator
  144.  
  145. %type <ttype> structsp component_decl_list component_decl components component_declarator
  146. %type <ttype> enumlist enumerator
  147. %type <ttype> typename absdcl absdcl1 type_quals
  148. %type <ttype> xexpr parms parm identifiers
  149.  
  150. %type <ttype> parmlist parmlist_1 parmlist_2
  151. %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
  152.  
  153. %type <itype> setspecs
  154.  
  155. %{
  156. /* the declaration found for the last IDENTIFIER token read in.
  157.    yylex must look this up to detect typedefs, which get token type TYPENAME,
  158.    so it is left around in case the identifier is not a typedef but is
  159.    used in a context which makes it a reference to a variable.  */
  160. static tree lastiddecl;
  161.  
  162. #if defined( _MSDOS )
  163. void error ( char *, ... );
  164. void warning ( char * s, ... );
  165. #endif
  166.  
  167. static tree make_pointer_declarator ();
  168. static tree combine_strings ();
  169. static void reinit_parse_for_function ();
  170.  
  171. /* List of types and structure classes of the current declaration.  */
  172. tree current_declspecs;
  173.  
  174. /* Stack of saved values of current_declspecs.  */
  175. tree declspec_stack;
  176.  
  177. int undeclared_variable_notice;    /* 1 if we explained undeclared var errors.  */
  178.  
  179. static int yylex ();
  180. %}
  181.  
  182. %%
  183. program: /* empty */
  184.     | extdefs
  185.     ;
  186.  
  187. /* the reason for the strange actions in this rule
  188.  is so that notype_initdecls when reached via datadef
  189.  can find a valid list of type and sc specs in $0. */
  190.  
  191. extdefs:
  192.     {$<ttype>$ = NULL_TREE; } extdef
  193.     | extdefs {$<ttype>$ = NULL_TREE; } extdef
  194.     ;
  195.  
  196. extdef:
  197.     fndef
  198.     | datadef
  199.     | ASM '(' string ')' ';'
  200.         { if (pedantic)
  201.             warning ("ANSI C forbids use of `asm' keyword");
  202.           if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  203.           assemble_asm ($3); }
  204.     ;
  205.  
  206. datadef:
  207.       setspecs notype_initdecls ';'
  208.         { if (pedantic)
  209.             error ("ANSI C forbids data definition lacking type or storage class");
  210.           else if (!flag_traditional)
  211.             warning ("data definition lacks type or storage class"); }
  212.         | declmods setspecs notype_initdecls ';'
  213.       {}
  214.     | typed_declspecs setspecs initdecls ';'
  215.       {}
  216.         | declmods ';'
  217.       { error ("empty declaration"); }
  218.     | typed_declspecs ';'
  219.       { shadow_tag ($1); }
  220.     | error ';'
  221.     | error '}'
  222.     | ';'
  223.         { if (pedantic)
  224.             warning ("ANSI C does not allow extra `;' outside of a function"); }
  225.     ;
  226.  
  227. fndef:
  228.       typed_declspecs setspecs declarator
  229.         { if (! start_function ($1, $3))
  230.             YYERROR;
  231.           reinit_parse_for_function (); }
  232.       xdecls
  233.         { store_parm_decls (); }
  234.       compstmt_or_error
  235.         { finish_function (lineno); }
  236.     | typed_declspecs setspecs declarator error
  237.         { }
  238.     | declmods setspecs notype_declarator
  239.         { if (! start_function ($1, $3))
  240.             YYERROR;
  241.           reinit_parse_for_function (); }
  242.       xdecls
  243.         { store_parm_decls (); }
  244.       compstmt_or_error
  245.         { finish_function (lineno); }
  246.     | declmods setspecs notype_declarator error
  247.         { }
  248.     | setspecs notype_declarator
  249.         { if (! start_function (0, $2))
  250.             YYERROR;
  251.           reinit_parse_for_function (); }
  252.       xdecls
  253.         { store_parm_decls (); }
  254.       compstmt_or_error
  255.         { finish_function (lineno); }
  256.     | setspecs notype_declarator error
  257.         { }
  258.     ;
  259.  
  260. identifier:
  261.     IDENTIFIER
  262.     | TYPENAME
  263.     ;
  264.  
  265. unop:     '&'
  266.         { $$ = ADDR_EXPR; }
  267.     | '-'
  268.         { $$ = NEGATE_EXPR; }
  269.     | '+'
  270.         { $$ = CONVERT_EXPR; }
  271.     | PLUSPLUS
  272.         { $$ = PREINCREMENT_EXPR; }
  273.     | MINUSMINUS
  274.         { $$ = PREDECREMENT_EXPR; }
  275.     | '~'
  276.         { $$ = BIT_NOT_EXPR; }
  277.     | '!'
  278.         { $$ = TRUTH_NOT_EXPR; }
  279.     ;
  280.  
  281. expr:    nonnull_exprlist
  282.         { $$ = build_compound_expr ($1); }
  283.     ;
  284.  
  285. exprlist:
  286.       /* empty */
  287.         { $$ = NULL_TREE; }
  288.     | nonnull_exprlist
  289.     ;
  290.  
  291. nonnull_exprlist:
  292.     expr_no_commas
  293.         { $$ = build_tree_list (NULL_TREE, $1); }
  294.     | nonnull_exprlist ',' expr_no_commas
  295.         { chainon ($1, build_tree_list (NULL_TREE, $3)); }
  296.     ;
  297.  
  298. unary_expr:
  299.     primary
  300.     | '*' cast_expr   %prec UNARY
  301.         { $$ = build_indirect_ref ($2, "unary *"); }
  302.     | unop cast_expr  %prec UNARY
  303.         { $$ = build_unary_op ($1, $2, 0); }
  304.     | SIZEOF unary_expr  %prec UNARY
  305.         { if (TREE_CODE ($2) == COMPONENT_REF
  306.               && TREE_PACKED (TREE_OPERAND ($2, 1)))
  307.             error ("`sizeof' applied to a bit-field");
  308.           /* ANSI says arrays and functions are converted inside comma.
  309.              But we can't really convert them in build_compound_expr
  310.              because that would break commas in lvalues.
  311.              So do the conversion here if operand was a comma.  */
  312.           if (TREE_CODE ($2) == COMPOUND_EXPR
  313.               && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
  314.               || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
  315.             $2 = default_conversion ($2);
  316.           $$ = c_sizeof (TREE_TYPE ($2)); }
  317.     | SIZEOF '(' typename ')'  %prec HYPERUNARY
  318.         { $$ = c_sizeof (groktypename ($3)); }
  319.     | ALIGNOF unary_expr  %prec UNARY
  320.         { if (TREE_CODE ($2) == COMPONENT_REF
  321.               && TREE_PACKED (TREE_OPERAND ($2, 1)))
  322.             error ("`__alignof' applied to a bit-field");
  323.           if (TREE_CODE ($2) == INDIRECT_REF)
  324.             {
  325.               tree t = TREE_OPERAND ($2, 0);
  326.               tree best = t;
  327.               int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  328.               while (TREE_CODE (t) == NOP_EXPR
  329.                  && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  330.             {
  331.               int thisalign;
  332.               t = TREE_OPERAND (t, 0);
  333.               thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  334.               if (thisalign > bestalign)
  335.                 best = t, bestalign = thisalign;
  336.             }
  337.               $$ = c_alignof (TREE_TYPE (TREE_TYPE (best)));
  338.             }
  339.           else
  340.             {
  341.               /* ANSI says arrays and fns are converted inside comma.
  342.              But we can't convert them in build_compound_expr
  343.              because that would break commas in lvalues.
  344.              So do the conversion here if operand was a comma.  */
  345.               if (TREE_CODE ($2) == COMPOUND_EXPR
  346.               && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE
  347.                   || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE))
  348.             $2 = default_conversion ($2);
  349.               $$ = c_alignof (TREE_TYPE ($2));
  350.             }
  351.         }
  352.     | ALIGNOF '(' typename ')'  %prec HYPERUNARY
  353.         { $$ = c_alignof (groktypename ($3)); }
  354.     ;
  355.  
  356. cast_expr:
  357.     unary_expr
  358.     | '(' typename ')' cast_expr  %prec UNARY
  359.         { tree type = groktypename ($2);
  360.           $$ = build_c_cast (type, $4); }
  361.     | '(' typename ')' '{' initlist maybecomma '}'  %prec UNARY
  362.         { tree type = groktypename ($2);
  363.           if (pedantic)
  364.             warning ("ANSI C forbids constructor expressions");
  365.           $$ = digest_init (type, build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($5)), 0);
  366.           if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
  367.             {
  368.               int failure = complete_array_type (type, $$, 1);
  369.               if (failure)
  370.             abort ();
  371.             }
  372.         }
  373.     ;
  374.  
  375. expr_no_commas:
  376.       cast_expr
  377.     | expr_no_commas '+' expr_no_commas
  378.         { $$ = build_binary_op ($2, $1, $3); }
  379.     | expr_no_commas '-' expr_no_commas
  380.         { $$ = build_binary_op ($2, $1, $3); }
  381.     | expr_no_commas '*' expr_no_commas
  382.         { $$ = build_binary_op ($2, $1, $3); }
  383.     | expr_no_commas '/' expr_no_commas
  384.         { $$ = build_binary_op ($2, $1, $3); }
  385.     | expr_no_commas '%' expr_no_commas
  386.         { $$ = build_binary_op ($2, $1, $3); }
  387.     | expr_no_commas LSHIFT expr_no_commas
  388.         { $$ = build_binary_op ($2, $1, $3); }
  389.     | expr_no_commas RSHIFT expr_no_commas
  390.         { $$ = build_binary_op ($2, $1, $3); }
  391.     | expr_no_commas ARITHCOMPARE expr_no_commas
  392.         { $$ = build_binary_op ($2, $1, $3); }
  393.     | expr_no_commas EQCOMPARE expr_no_commas
  394.         { $$ = build_binary_op ($2, $1, $3); }
  395.     | expr_no_commas '&' expr_no_commas
  396.         { $$ = build_binary_op ($2, $1, $3); }
  397.     | expr_no_commas '|' expr_no_commas
  398.         { $$ = build_binary_op ($2, $1, $3); }
  399.     | expr_no_commas '^' expr_no_commas
  400.         { $$ = build_binary_op ($2, $1, $3); }
  401.     | expr_no_commas ANDAND expr_no_commas
  402.         { $$ = build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); }
  403.     | expr_no_commas OROR expr_no_commas
  404.         { $$ = build_binary_op (TRUTH_ORIF_EXPR, $1, $3); }
  405.     | expr_no_commas '?' xexpr ':' expr_no_commas
  406.         { $$ = build_conditional_expr ($1, $3, $5); }
  407.     | expr_no_commas '=' expr_no_commas
  408.         { $$ = build_modify_expr ($1, NOP_EXPR, $3); }
  409.     | expr_no_commas ASSIGN expr_no_commas
  410.         { $$ = build_modify_expr ($1, $2, $3); }
  411.     ;
  412.  
  413. primary:
  414.     IDENTIFIER
  415.         { $$ = lastiddecl;
  416.           if (!$$ || $$ == error_mark_node)
  417.             {
  418.               if (yychar == YYEMPTY)
  419.             yychar = YYLEX;
  420.               if (yychar == '(')
  421.             {
  422.               $$ = implicitly_declare ($1);
  423.               assemble_external ($$);
  424.               TREE_USED ($$) = 1;
  425.             }
  426.               else if (current_function_decl == 0)
  427.             {
  428.               error ("`%s' undeclared, outside of functions",
  429.                  IDENTIFIER_POINTER ($1));
  430.               $$ = error_mark_node;
  431.             }
  432.               else
  433.             {
  434.               if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node
  435.                   || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl)
  436.                 {
  437.                   error ("`%s' undeclared (first use this function)",
  438.                      IDENTIFIER_POINTER ($1));
  439.  
  440.                   if (! undeclared_variable_notice)
  441.                 {
  442.                   error ("(Each undeclared identifier is reported only once");
  443.                   error ("for each function it appears in.)");
  444.                   undeclared_variable_notice = 1;
  445.                 }
  446.                 }
  447.               $$ = error_mark_node;
  448.               /* Prevent repeated error messages.  */
  449.               IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node;
  450.               IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl;
  451.             }
  452.             }
  453.           else if (! TREE_USED ($$))
  454.             {
  455.               if (TREE_EXTERNAL ($$))
  456.             assemble_external ($$);
  457.               TREE_USED ($$) = 1;
  458.             }
  459.           if (TREE_CODE ($$) == CONST_DECL)
  460.             $$ = DECL_INITIAL ($$);
  461.         }
  462.     | CONSTANT
  463.     | string
  464.         { $$ = combine_strings ($1); }
  465.     | '(' expr ')'
  466.         { $$ = $2; }
  467.     | '(' error ')'
  468.         { $$ = error_mark_node; }
  469.     | '('
  470.         { if (current_function_decl == 0)
  471.             {
  472.               error ("braced-group within expression allowed only inside a function");
  473.               YYERROR;
  474.             }
  475.           keep_next_level ();
  476.           $<ttype>$ = expand_start_stmt_expr (); }
  477.       compstmt ')'
  478.         { tree rtl_exp;
  479.           if (pedantic)
  480.             warning ("ANSI C forbids braced-groups within expressions");
  481.           rtl_exp = expand_end_stmt_expr ($<ttype>2);
  482.           $$ = $3;
  483.           TREE_USED ($$) = 0;
  484.           /* Since the statements have side effects,
  485.              consider this volatile.  */
  486.           TREE_VOLATILE ($$) = 1;
  487.           TREE_TYPE ($$) = TREE_TYPE (rtl_exp);
  488.           STMT_BODY ($$) = rtl_exp; }
  489.     | primary '(' exprlist ')'   %prec '.'
  490.         { $$ = build_function_call ($1, $3); }
  491.     | primary '[' expr ']'   %prec '.'
  492.         { $$ = build_array_ref ($1, $3); }
  493.     | primary '.' identifier
  494.         { $$ = build_component_ref ($1, $3); }
  495.     | primary POINTSAT identifier
  496.         { $$ = build_component_ref (build_indirect_ref ($1, "->"), $3); }
  497.     | primary PLUSPLUS
  498.         { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
  499.     | primary MINUSMINUS
  500.         { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
  501.     ;
  502.  
  503. /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it.  */
  504. string:
  505.       STRING
  506.     | string STRING
  507.         { $$ = chainon ($1, $2); }
  508.     ;
  509.  
  510. xdecls:
  511.     /* empty */
  512.     | decls
  513.     ;
  514.  
  515. decls:
  516.     decl
  517.     | errstmt
  518.     | decls decl
  519.     | decl errstmt
  520.     ;
  521.  
  522. /* records the type and storage class specs to use for processing
  523.    the declarators that follow.
  524.    Maintains a stack of outer-level values of current_declspecs,
  525.    for the sake of parm declarations nested in function declarators.  */
  526. setspecs: /* empty */
  527.         { $$ = suspend_momentary ();
  528.           declspec_stack = tree_cons (0, current_declspecs,
  529.                           declspec_stack);
  530.           current_declspecs = $<ttype>0; }
  531.     ;
  532.  
  533. decl:
  534.     typed_declspecs setspecs initdecls ';'
  535.         { current_declspecs = TREE_VALUE (declspec_stack);
  536.           declspec_stack = TREE_CHAIN (declspec_stack);
  537.           resume_momentary ($2); }
  538.     | declmods setspecs notype_initdecls ';'
  539.         { current_declspecs = TREE_VALUE (declspec_stack);
  540.           declspec_stack = TREE_CHAIN (declspec_stack);
  541.           resume_momentary ($2); }
  542.     | typed_declspecs ';'
  543.         { shadow_tag ($1); }
  544.     | declmods ';'
  545.         { warning ("empty declaration"); }
  546.     ;
  547.  
  548. /* Declspecs which contain at least one type specifier or typedef name.
  549.    (Just `const' or `volatile' is not enough.)
  550.    A typedef'd name following these is taken as a name to be declared.  */
  551.  
  552. typed_declspecs:
  553.       typespec reserved_declspecs
  554.         { $$ = tree_cons (NULL_TREE, $1, $2); }
  555.     | declmods typespec reserved_declspecs
  556.         { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  557.     ;
  558.  
  559. reserved_declspecs:  /* empty */
  560.         { $$ = NULL_TREE; }
  561.     | reserved_declspecs typespecqual_reserved
  562.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  563.     | reserved_declspecs SCSPEC
  564.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  565.     ;
  566.  
  567. /* List of just storage classes and type modifiers.
  568.    A declaration can start with just this, but then it cannot be used
  569.    to redeclare a typedef-name.  */
  570.  
  571. declmods:
  572.       TYPE_QUAL
  573.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  574.     | SCSPEC
  575.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  576.     | declmods TYPE_QUAL
  577.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  578.     | declmods SCSPEC
  579.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  580.     ;
  581.  
  582.  
  583. /* Used instead of declspecs where storage classes are not allowed
  584.    (that is, for typenames and structure components).
  585.    Don't accept a typedef-name if anything but a modifier precedes it.  */
  586.  
  587. typed_typespecs:
  588.       typespec reserved_typespecquals
  589.         { $$ = tree_cons (NULL_TREE, $1, $2); }
  590.     | nonempty_type_quals typespec reserved_typespecquals
  591.         { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
  592.     ;
  593.  
  594. reserved_typespecquals:  /* empty */
  595.         { $$ = NULL_TREE; }
  596.     | reserved_typespecquals typespecqual_reserved
  597.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  598.     ;
  599.  
  600. /* A typespec (but not a type qualifier).
  601.    Once we have seen one of these in a declaration,
  602.    if a typedef name appears then it is being redeclared.  */
  603.  
  604. typespec: TYPESPEC
  605.     | structsp
  606.     | TYPENAME
  607.     | TYPEOF '(' expr ')'
  608.         { $$ = TREE_TYPE ($3);
  609.           if (pedantic)
  610.             warning ("ANSI C forbids `typeof'"); }
  611.     | TYPEOF '(' typename ')'
  612.         { $$ = groktypename ($3);
  613.           if (pedantic)
  614.             warning ("ANSI C forbids `typeof'"); }
  615.     ;
  616.  
  617. /* A typespec that is a reserved word, or a type qualifier.  */
  618.  
  619. typespecqual_reserved: TYPESPEC
  620.     | TYPE_QUAL
  621.     | structsp
  622.     ;
  623.  
  624. initdecls:
  625.     initdcl
  626.     | initdecls ',' initdcl
  627.     ;
  628.  
  629. notype_initdecls:
  630.     notype_initdcl
  631.     | notype_initdecls ',' initdcl
  632.     ;
  633.  
  634. maybeasm:
  635.       /* empty */
  636.         { $$ = NULL_TREE; }
  637.     | ASM '(' string ')'
  638.         { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
  639.           $$ = $3;
  640.           if (pedantic)
  641.             warning ("ANSI C forbids use of `asm' keyword");
  642.         }
  643.     ;
  644.  
  645. initdcl:
  646.       declarator maybeasm maybe_attribute '='
  647.         { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
  648.       init
  649. /* Note how the declaration of the variable is in effect while its init is parsed! */
  650.         { finish_decl ($<ttype>5, $6, $2); }
  651.     | declarator maybeasm maybe_attribute
  652.         { tree d = start_decl ($1, current_declspecs, 0);
  653.           finish_decl (d, NULL_TREE, $2); }
  654.     ;
  655.  
  656. notype_initdcl:
  657.       notype_declarator maybeasm maybe_attribute '='
  658.         { $<ttype>$ = start_decl ($1, current_declspecs, 1); }
  659.       init
  660. /* Note how the declaration of the variable is in effect while its init is parsed! */
  661.         { finish_decl ($<ttype>5, $6, $2); }
  662.     | notype_declarator maybeasm maybe_attribute
  663.         { tree d = start_decl ($1, current_declspecs, 0);
  664.           finish_decl (d, NULL_TREE, $2); }
  665.     ;
  666. /* the * rules are dummies to accept the Apollo extended syntax
  667.    so that the header files compile. */
  668. maybe_attribute:
  669.     /* empty */
  670.     { $$ = NULL_TREE; }
  671.     | ATTRIBUTE '(' '(' attribute_list ')' ')'
  672.         { $$ = $4; }
  673.     ;
  674.  
  675. attribute_list
  676.     : attrib
  677.     | attribute_list ',' attrib
  678.     ;
  679.  
  680. attrib
  681.     : IDENTIFIER
  682.     { warning ("`%s' attribute directive ignored",
  683.            IDENTIFIER_POINTER ($1));
  684.       $$ = $1; }
  685.     | IDENTIFIER '(' CONSTANT ')'
  686.     { /* if not "aligned(1)", then issue warning */
  687.       if (strcmp (IDENTIFIER_POINTER ($1), "aligned") != 0
  688.           || TREE_CODE ($3) != INTEGER_CST
  689.           || TREE_INT_CST_LOW ($3) != 1)
  690.         warning ("`%s' attribute directive ignored",
  691.              IDENTIFIER_POINTER ($1));
  692.       $$ = $1; }
  693.     | IDENTIFIER '(' identifiers ')'
  694.     { warning ("`%s' attribute directive ignored",
  695.            IDENTIFIER_POINTER ($1));
  696.       $$ = $1; }
  697.     ;
  698.  
  699. init:
  700.     expr_no_commas
  701.     | '{' '}'
  702.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  703.           if (pedantic)
  704.             warning ("ANSI C forbids empty initializer braces"); }
  705.     | '{' initlist '}'
  706.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
  707.     | '{' initlist ',' '}'
  708.         { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); }
  709.     | error
  710.         { $$ = NULL_TREE; }
  711.     ;
  712.  
  713. /* This chain is built in reverse order,
  714.    and put in forward order where initlist is used.  */
  715. initlist:
  716.       init
  717.         { $$ = build_tree_list (NULL_TREE, $1); }
  718.     | initlist ',' init
  719.         { $$ = tree_cons (NULL_TREE, $3, $1); }
  720.     ;
  721.  
  722. /* Any kind of declarator (thus, all declarators allowed
  723.    after an explicit typespec).  */
  724.  
  725. declarator:
  726.       after_type_declarator
  727.     | notype_declarator
  728.     ;
  729.  
  730. /* A declarator that is allowed only after an explicit typespec.  */
  731.  
  732. after_type_declarator:
  733.       '(' after_type_declarator ')'
  734.         { $$ = $2; }
  735.     | after_type_declarator '(' parmlist_or_identifiers  %prec '.'
  736.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  737. /*    | after_type_declarator '(' error ')'  %prec '.'
  738.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  739.           poplevel (0, 0, 0); }  */
  740.     | after_type_declarator '[' expr ']'  %prec '.'
  741.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  742.     | after_type_declarator '[' ']'  %prec '.'
  743.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  744.     | '*' type_quals after_type_declarator  %prec UNARY
  745.         { $$ = make_pointer_declarator ($2, $3); }
  746.     | TYPENAME
  747.     ;
  748.  
  749. /* Kinds of declarator that can appear in a parameter list
  750.    in addition to notype_declarator.  This is like after_type_declarator
  751.    but does not allow a typedef name in parentheses as an identifier
  752.    (because it would conflict with a function with that typedef as arg).  */
  753.  
  754. parm_declarator:
  755.       parm_declarator '(' parmlist_or_identifiers  %prec '.'
  756.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  757. /*    | parm_declarator '(' error ')'  %prec '.'
  758.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  759.           poplevel (0, 0, 0); }  */
  760.     | parm_declarator '[' expr ']'  %prec '.'
  761.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  762.     | parm_declarator '[' ']'  %prec '.'
  763.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  764.     | '*' type_quals parm_declarator  %prec UNARY
  765.         { $$ = make_pointer_declarator ($2, $3); }
  766.     | TYPENAME
  767.     ;
  768.  
  769. /* A declarator allowed whether or not there has been
  770.    an explicit typespec.  These cannot redeclare a typedef-name.  */
  771.  
  772. notype_declarator:
  773.       notype_declarator '(' parmlist_or_identifiers  %prec '.'
  774.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  775. /*    | notype_declarator '(' error ')'  %prec '.'
  776.         { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
  777.           poplevel (0, 0, 0); }  */
  778.     | '(' notype_declarator ')'
  779.         { $$ = $2; }
  780.     | '*' type_quals notype_declarator  %prec UNARY
  781.         { $$ = make_pointer_declarator ($2, $3); }
  782.     | notype_declarator '[' expr ']'  %prec '.'
  783.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  784.     | notype_declarator '[' ']'  %prec '.'
  785.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  786.     | IDENTIFIER
  787.     ;
  788.  
  789. structsp:
  790.       STRUCT identifier '{'
  791.         { $$ = start_struct (RECORD_TYPE, $2);
  792.           /* Start scope of tag before parsing components.  */
  793.         }
  794.       component_decl_list '}'
  795.         { $$ = finish_struct ($<ttype>4, $5);
  796.           /* Really define the structure.  */
  797.         }
  798.     | STRUCT '{' component_decl_list '}'
  799.         { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
  800.                       $3); }
  801.     | STRUCT identifier
  802.         { $$ = xref_tag (RECORD_TYPE, $2); }
  803.     | UNION identifier '{'
  804.         { $$ = start_struct (UNION_TYPE, $2); }
  805.       component_decl_list '}'
  806.         { $$ = finish_struct ($<ttype>4, $5); }
  807.     | UNION '{' component_decl_list '}'
  808.         { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
  809.                       $3); }
  810.     | UNION identifier
  811.         { $$ = xref_tag (UNION_TYPE, $2); }
  812.     | ENUM identifier '{'
  813.         { $<itype>3 = suspend_momentary ();
  814.           $$ = start_enum ($2); }
  815.       enumlist maybecomma_warn '}'
  816.         { $$ = finish_enum ($<ttype>4, nreverse ($5));
  817.           resume_momentary ($<itype>3); }
  818.     | ENUM '{'
  819.         { $<itype>2 = suspend_momentary ();
  820.           $$ = start_enum (NULL_TREE); }
  821.       enumlist maybecomma_warn '}'
  822.         { $$ = finish_enum ($<ttype>3, nreverse ($4));
  823.           resume_momentary ($<itype>2); }
  824.     | ENUM identifier
  825.         { $$ = xref_tag (ENUMERAL_TYPE, $2); }
  826.     ;
  827.  
  828. maybecomma:
  829.       /* empty */
  830.     | ','
  831.     ;
  832.  
  833. maybecomma_warn:
  834.       /* empty */
  835.     | ','
  836.         { if (pedantic) warning ("comma at end of enumerator list"); }
  837.     ;
  838.  
  839. component_decl_list:   /* empty */
  840.         { $$ = NULL_TREE; }
  841.     | component_decl_list component_decl ';'
  842.         { $$ = chainon ($1, $2); }
  843.     | component_decl_list ';'
  844.         { if (pedantic)
  845.             warning ("extra semicolon in struct or union specified"); }
  846.     ;
  847.  
  848. /* There is a shift-reduce conflict here, because `components' may
  849.    start with a `typename'.  It happens that shifting (the default resolution)
  850.    does the right thing, because it treats the `typename' as part of
  851.    a `typed_typespecs'.
  852.  
  853.    It is possible that this same technique would allow the distinction
  854.    between `notype_initdecls' and `initdecls' to be eliminated.
  855.    But I am being cautious and not trying it.  */
  856.  
  857. component_decl:
  858.     typed_typespecs setspecs components
  859.         { $$ = $3;
  860.           current_declspecs = TREE_VALUE (declspec_stack);
  861.           declspec_stack = TREE_CHAIN (declspec_stack);
  862.           resume_momentary ($2); }
  863.     | nonempty_type_quals setspecs components
  864.         { $$ = $3;
  865.           current_declspecs = TREE_VALUE (declspec_stack);
  866.           declspec_stack = TREE_CHAIN (declspec_stack);
  867.           resume_momentary ($2); }
  868.     | error
  869.         { $$ = NULL_TREE; }
  870.     ;
  871.  
  872. components:
  873.       /* empty */
  874.         { if (pedantic)
  875.             warning ("ANSI C forbids member declarations with no members");
  876.           $$ = NULL_TREE; }
  877.     | component_declarator
  878.     | components ',' component_declarator
  879.         { $$ = chainon ($1, $3); }
  880.     ;
  881.  
  882. component_declarator:
  883.     declarator maybe_attribute
  884.         { $$ = grokfield (input_filename, lineno, $1, current_declspecs, NULL_TREE); }
  885.     | declarator ':' expr_no_commas maybe_attribute
  886.         { $$ = grokfield (input_filename, lineno, $1, current_declspecs, $3); }
  887.     | ':' expr_no_commas
  888.         { $$ = grokfield (input_filename, lineno, NULL_TREE, current_declspecs, $2); }
  889.     ;
  890.  
  891. /* We chain the enumerators in reverse order.
  892.    They are put in forward order where enumlist is used.
  893.    (The order used to be significant, but no longer is so.
  894.    However, we still maintain the order, just to be clean.)  */
  895.  
  896. enumlist:
  897.       enumerator
  898.     | enumlist ',' enumerator
  899.         { $$ = chainon ($3, $1); }
  900.     ;
  901.  
  902.  
  903. enumerator:
  904.       identifier
  905.         { $$ = build_enumerator ($1, NULL_TREE); }
  906.     | identifier '=' expr_no_commas
  907.         { $$ = build_enumerator ($1, $3); }
  908.     ;
  909.  
  910. typename:
  911.     typed_typespecs absdcl
  912.         { $$ = build_tree_list ($1, $2); }
  913.     | nonempty_type_quals absdcl
  914.         { $$ = build_tree_list ($1, $2); }
  915.     ;
  916.  
  917. absdcl:   /* an absolute declarator */
  918.     /* empty */
  919.         { $$ = NULL_TREE; }
  920.     | absdcl1
  921.     ;
  922.  
  923. nonempty_type_quals:
  924.       TYPE_QUAL
  925.         { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
  926.     | nonempty_type_quals TYPE_QUAL
  927.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  928.     ;
  929.  
  930. type_quals:
  931.       /* empty */
  932.         { $$ = NULL_TREE; }
  933.     | type_quals TYPE_QUAL
  934.         { $$ = tree_cons (NULL_TREE, $2, $1); }
  935.     ;
  936.  
  937. absdcl1:  /* a nonempty absolute declarator */
  938.       '(' absdcl1 ')'
  939.         { $$ = $2; }
  940.       /* `(typedef)1' is `int'.  */
  941.     | '*' type_quals absdcl1  %prec UNARY
  942.         { $$ = make_pointer_declarator ($2, $3); }
  943.     | '*' type_quals  %prec UNARY
  944.         { $$ = make_pointer_declarator ($2, NULL_TREE); }
  945.     | absdcl1 '(' parmlist  %prec '.'
  946.         { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
  947.     | absdcl1 '[' expr ']'  %prec '.'
  948.         { $$ = build_nt (ARRAY_REF, $1, $3); }
  949.     | absdcl1 '[' ']'  %prec '.'
  950.         { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
  951.     | '(' parmlist  %prec '.'
  952.         { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
  953.     | '[' expr ']'  %prec '.'
  954.         { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
  955.     | '[' ']'  %prec '.'
  956.         { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
  957.     ;
  958.  
  959. /* at least one statement, the first of which parses without error.  */
  960. /* stmts is used only after decls, so an invalid first statement
  961.    is actually regarded as an invalid decl and part of the decls.  */
  962.  
  963. stmts:
  964.     stmt
  965.     | stmts stmt
  966.     | stmts errstmt
  967.     ;
  968.  
  969. xstmts:
  970.     /* empty */
  971.     | stmts
  972.     ;
  973.  
  974. errstmt:  error ';'
  975.     ;
  976.  
  977. pushlevel:  /* empty */
  978.         { pushlevel (0);
  979.           clear_last_expr ();
  980.           push_momentary ();
  981.           expand_start_bindings (0); }
  982.     ;
  983.  
  984. /* This is the body of a function definition.
  985.    It causes syntax errors to ignore to the next openbrace.  */
  986. compstmt_or_error:
  987.       compstmt
  988.         {}
  989.     | error compstmt
  990.     ;
  991.  
  992. compstmt: '{' '}'
  993.         { $$ = 0; }
  994.     | '{' pushlevel decls xstmts '}'
  995.         { expand_end_bindings (getdecls (), 1, 0);
  996.           $$ = poplevel (1, 1, 0);
  997.           pop_momentary (); }
  998.     | '{' pushlevel error '}'
  999.         { expand_end_bindings (getdecls (), kept_level_p (), 0);
  1000.           $$ = poplevel (kept_level_p (), 0, 0);
  1001.           pop_momentary (); }
  1002.     | '{' pushlevel stmts '}'
  1003.         { expand_end_bindings (getdecls (), kept_level_p (), 0);
  1004.           $$ = poplevel (kept_level_p (), 0, 0);
  1005.           pop_momentary (); }
  1006.     ;
  1007.  
  1008. simple_if:
  1009.       IF '(' expr ')'
  1010.         { emit_line_note (input_filename, lineno);
  1011.           expand_start_cond (truthvalue_conversion ($3), 0); }
  1012.       stmt
  1013.     ;
  1014.  
  1015. stmt:
  1016.       compstmt    {}
  1017.     | expr ';'
  1018.         { emit_line_note (input_filename, lineno);
  1019.           /* Do default conversion if safe and possibly important,
  1020.              in case within ({...}).  */
  1021.           if ((TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE
  1022.                && lvalue_p ($1))
  1023.               || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE)
  1024.             $1 = default_conversion ($1);
  1025.           expand_expr_stmt ($1);
  1026.           clear_momentary (); }
  1027.     | simple_if ELSE
  1028.         { expand_start_else (); }
  1029.       stmt
  1030.         { expand_end_else (); }
  1031.     | simple_if %prec IF
  1032.         { expand_end_cond (); }
  1033.     | WHILE
  1034.         { emit_nop ();
  1035.           emit_line_note (input_filename, lineno);
  1036.           expand_start_loop (1); }
  1037.       '(' expr ')'
  1038.         { emit_line_note (input_filename, lineno);
  1039.           expand_exit_loop_if_false (truthvalue_conversion ($4)); }
  1040.       stmt
  1041.         { expand_end_loop (); }
  1042.     | DO
  1043.         { emit_nop ();
  1044.           emit_line_note (input_filename, lineno);
  1045.           expand_start_loop_continue_elsewhere (1); }
  1046.       stmt WHILE
  1047.         { expand_loop_continue_here (); }
  1048.       '(' expr ')' ';'
  1049.         { emit_line_note (input_filename, lineno);
  1050.           expand_exit_loop_if_false (truthvalue_conversion ($7));
  1051.           expand_end_loop ();
  1052.           clear_momentary (); }
  1053.     | FOR
  1054.       '(' xexpr ';'
  1055.         { emit_nop ();
  1056.           emit_line_note (input_filename, lineno);
  1057.           if ($3) expand_expr_stmt ($3);
  1058.           expand_start_loop_continue_elsewhere (1); }
  1059.       xexpr ';'
  1060.         { emit_line_note (input_filename, lineno);
  1061.           if ($6)
  1062.             expand_exit_loop_if_false (truthvalue_conversion ($6)); }
  1063.       xexpr ')'
  1064.         /* Don't let the tree nodes for $9 be discarded
  1065.            by clear_momentary during the parsing of the next stmt.  */
  1066.         { push_momentary ();
  1067.           $<itype>10 = lineno; }
  1068.       stmt
  1069.         { emit_line_note (input_filename, $<itype>10);
  1070.           expand_loop_continue_here ();
  1071.           if ($9)
  1072.             expand_expr_stmt ($9);
  1073.           pop_momentary ();
  1074.           expand_end_loop (); }
  1075.     | SWITCH '(' expr ')'
  1076.         { emit_line_note (input_filename, lineno);
  1077.           c_expand_start_case ($3);
  1078.           /* Don't let the tree nodes for $3 be discarded by
  1079.              clear_momentary during the parsing of the next stmt.  */
  1080.           push_momentary (); }
  1081.       stmt
  1082.         { expand_end_case ($3);
  1083.           pop_momentary (); }
  1084.     | CASE expr ':'
  1085.         { register tree value = fold ($2);
  1086.           register tree label
  1087.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  1088.  
  1089.           /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
  1090.              Strip such NOP_EXPRs.  */
  1091.           if (TREE_CODE (value) == NOP_EXPR
  1092.               && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  1093.             value = TREE_OPERAND (value, 0);
  1094.  
  1095.           if (TREE_CODE (value) != INTEGER_CST
  1096.               && value != error_mark_node)
  1097.             {
  1098.               error ("case label does not reduce to an integer constant");
  1099.               value = error_mark_node;
  1100.             }
  1101.           else
  1102.             /* Promote char or short to int.  */
  1103.             value = default_conversion (value);
  1104.           if (value != error_mark_node)
  1105.             {
  1106.               int success = pushcase (value, label);
  1107.               if (success == 1)
  1108.             error ("case label not within a switch statement");
  1109.               else if (success == 2)
  1110.             error ("duplicate case value");
  1111.               else if (success == 3)
  1112.             warning ("case value out of range");
  1113.             }
  1114.         }
  1115.       stmt
  1116.     | DEFAULT ':'
  1117.         {
  1118.           register tree label
  1119.             = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  1120.           int success = pushcase (NULL_TREE, label);
  1121.           if (success == 1)
  1122.             error ("default label not within a switch statement");
  1123.           else if (success == 2)
  1124.             error ("multiple default labels in one switch");
  1125.         }
  1126.       stmt
  1127.     | BREAK ';'
  1128.         { emit_line_note (input_filename, lineno);
  1129.           if ( ! expand_exit_something ())
  1130.             error ("break statement not within loop or switch"); }
  1131.     | CONTINUE ';'
  1132.         { emit_line_note (input_filename, lineno);
  1133.           if (! expand_continue_loop ())
  1134.             error ("continue statement not within a loop"); }
  1135.     | RETURN ';'
  1136.         { emit_line_note (input_filename, lineno);
  1137.           c_expand_return (NULL_TREE); }
  1138.     | RETURN expr ';'
  1139.         { emit_line_note (input_filename, lineno);
  1140.           c_expand_return ($2); }
  1141.     | ASM maybe_type_qual '(' string ')' ';'
  1142.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  1143.           emit_line_note (input_filename, lineno);
  1144.           expand_asm ($4); }
  1145.     /* This is the case with just output operands.  */
  1146.     | ASM maybe_type_qual '(' string ':' asm_operands ')' ';'
  1147.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  1148.           emit_line_note (input_filename, lineno);
  1149.           c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
  1150.                      $2 == ridpointers[(int)RID_VOLATILE],
  1151.                      input_filename, lineno); }
  1152.     /* This is the case with input operands as well.  */
  1153.     | ASM maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';'
  1154.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  1155.           emit_line_note (input_filename, lineno);
  1156.           c_expand_asm_operands ($4, $6, $8, NULL_TREE,
  1157.                      $2 == ridpointers[(int)RID_VOLATILE],
  1158.                      input_filename, lineno); }
  1159.     /* This is the case with clobbered registers as well.  */
  1160.     | ASM maybe_type_qual '(' string ':' asm_operands ':'
  1161.         asm_operands ':' asm_clobbers ')' ';'
  1162.         { if (TREE_CHAIN ($4)) $4 = combine_strings ($4);
  1163.           emit_line_note (input_filename, lineno);
  1164.           c_expand_asm_operands ($4, $6, $8, $10,
  1165.                      $2 == ridpointers[(int)RID_VOLATILE],
  1166.                      input_filename, lineno); }
  1167.     | GOTO identifier ';'
  1168.         { tree decl;
  1169.           emit_line_note (input_filename, lineno);
  1170.           decl = lookup_label ($2);
  1171.           TREE_USED (decl) = 1;
  1172.           expand_goto (decl); }
  1173.     | identifier ':'
  1174.         { tree label = define_label (input_filename, lineno, $1);
  1175.           emit_nop ();
  1176.           if (label)
  1177.             expand_label (label); }
  1178.       stmt
  1179.     | ';'
  1180.     ;
  1181.  
  1182. /* Either a type-qualifier or nothing.  First thing in an `asm' statement.  */
  1183.  
  1184. maybe_type_qual:
  1185.     /* empty */
  1186.         { if (pedantic)
  1187.             warning ("ANSI C forbids use of `asm' keyword");
  1188.           emit_line_note (input_filename, lineno); }
  1189.     | TYPE_QUAL
  1190.         { if (pedantic)
  1191.             warning ("ANSI C forbids use of `asm' keyword");
  1192.           emit_line_note (input_filename, lineno); }
  1193.     ;
  1194.  
  1195. xexpr:
  1196.     /* empty */
  1197.         { $$ = NULL_TREE; }
  1198.     | expr
  1199.     ;
  1200.  
  1201. /* These are the operands other than the first string and colon
  1202.    in  asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x))  */
  1203. asm_operands: /* empty */
  1204.         { $$ = NULL_TREE; }
  1205.     | nonnull_asm_operands
  1206.     ;
  1207.  
  1208. nonnull_asm_operands:
  1209.       asm_operand
  1210.     | nonnull_asm_operands ',' asm_operand
  1211.         { $$ = chainon ($1, $3); }
  1212.     ;
  1213.  
  1214. asm_operand:
  1215.       STRING '(' expr ')'
  1216.         { $$ = build_tree_list ($1, $3); }
  1217.     ;
  1218.  
  1219. asm_clobbers:
  1220.       string
  1221.         { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
  1222.     | asm_clobbers ',' string
  1223.         { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
  1224.     ;
  1225.  
  1226. /* This is what appears inside the parens in a function declarator.
  1227.    Its value is a list of ..._TYPE nodes.  */
  1228. parmlist:
  1229.         { pushlevel (0);
  1230.           declare_parm_level (); }
  1231.       parmlist_1
  1232.         { $$ = $2;
  1233.           parmlist_tags_warning ();
  1234.           poplevel (0, 0, 0); }
  1235.     ;
  1236.  
  1237. /* This is referred to where either a parmlist or an identifier list is ok.
  1238.    Its value is a list of ..._TYPE nodes or a list of identifiers.  */
  1239. parmlist_or_identifiers:
  1240.         { pushlevel (0);
  1241.           declare_parm_level (); }
  1242.       parmlist_or_identifiers_1
  1243.         { $$ = $2;
  1244.           parmlist_tags_warning ();
  1245.           poplevel (0, 0, 0); }
  1246.     ;
  1247.  
  1248. parmlist_or_identifiers_1:
  1249.       parmlist_2 ')'
  1250.     | identifiers ')'
  1251.         { $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
  1252.     | error ')'
  1253.         { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
  1254.     ;
  1255.  
  1256. parmlist_1:
  1257.       parmlist_2 ')'
  1258.     | error ')'
  1259.         { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
  1260.     ;
  1261.  
  1262. /* This is what appears inside the parens in a function declarator.
  1263.    Is value is represented in the format that grokdeclarator expects.  */
  1264. parmlist_2:  /* empty */
  1265.         { $$ = get_parm_info (0); }
  1266.     | parms
  1267.         { $$ = get_parm_info (1); }
  1268.     | parms ',' ELLIPSIS
  1269.         { $$ = get_parm_info (0); }
  1270.     ;
  1271.  
  1272. parms:
  1273.     parm
  1274.         { push_parm_decl ($1); }
  1275.     | parms ',' parm
  1276.         { push_parm_decl ($3); }
  1277.     ;
  1278.  
  1279. /* A single parameter declaration or parameter type name,
  1280.    as found in a parmlist.  */
  1281. parm:
  1282.       typed_declspecs parm_declarator
  1283.         { $$ = build_tree_list ($1, $2)    ; }
  1284.     | typed_declspecs notype_declarator
  1285.         { $$ = build_tree_list ($1, $2)    ; }
  1286.     | typed_declspecs absdcl
  1287.         { $$ = build_tree_list ($1, $2); }
  1288.     | declmods notype_declarator
  1289.         { $$ = build_tree_list ($1, $2)    ; }
  1290.     | declmods absdcl
  1291.         { $$ = build_tree_list ($1, $2); }
  1292.     ;
  1293.  
  1294. /* A nonempty list of identifiers.  */
  1295. identifiers:
  1296.     IDENTIFIER
  1297.         { $$ = build_tree_list (NULL_TREE, $1); }
  1298.     | identifiers ',' IDENTIFIER
  1299.         { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
  1300.     ;
  1301. %%
  1302.  
  1303. /* Return something to represent absolute declarators containing a *.
  1304.    TARGET is the absolute declarator that the * contains.
  1305.    TYPE_QUALS is a list of modifiers such as const or volatile
  1306.    to apply to the pointer type, represented as identifiers.
  1307.  
  1308.    We return an INDIRECT_REF whose "contents" are TARGET
  1309.    and whose type is the modifier list.  */
  1310.  
  1311. static tree
  1312. make_pointer_declarator (type_quals, target)
  1313.      tree type_quals, target;
  1314. {
  1315.   return build (INDIRECT_REF, type_quals, target);
  1316. }
  1317.  
  1318. /* Given a chain of STRING_CST nodes,
  1319.    concatenate them into one STRING_CST
  1320.    and give it a suitable array-of-chars data type.  */
  1321.  
  1322. static tree
  1323. combine_strings (strings)
  1324.      tree strings;
  1325. {
  1326.   register tree value, t;
  1327.   register int length = 1;
  1328.   int wide_length = 0;
  1329.   int wide_flag = 0;
  1330.  
  1331.   if (TREE_CHAIN (strings))
  1332.     {
  1333.       /* More than one in the chain, so concatenate.  */
  1334.       register char *p, *q;
  1335.  
  1336.       /* Don't include the \0 at the end of each substring,
  1337.      except for the last one.
  1338.      Count wide strings and ordinary strings separately.  */
  1339.       for (t = strings; t; t = TREE_CHAIN (t))
  1340.     {
  1341.       if (TREE_TYPE (t) == int_array_type_node)
  1342.         {
  1343.           wide_length += (TREE_STRING_LENGTH (t) - 1);
  1344.           wide_flag = 1;
  1345.         }
  1346.       else
  1347.         length += (TREE_STRING_LENGTH (t) - 1);
  1348.     }
  1349.  
  1350.       /* If anything is wide, the non-wides will be converted,
  1351.      which makes them take more space.  */
  1352.       if (wide_flag)
  1353.     length = length * UNITS_PER_WORD + wide_length;
  1354.  
  1355.       p = (char *) savealloc (length);
  1356.  
  1357.       /* Copy the individual strings into the new combined string.
  1358.      If the combined string is wide, convert the chars to ints
  1359.      for any individual strings that are not wide.  */
  1360.  
  1361.       q = p;
  1362.       for (t = strings; t; t = TREE_CHAIN (t))
  1363.     {
  1364.       int len = TREE_STRING_LENGTH (t) - 1;
  1365.       if ((TREE_TYPE (t) == int_array_type_node) == wide_flag)
  1366.         {
  1367.           bcopy (TREE_STRING_POINTER (t), q, len);
  1368.           q += len;
  1369.         }
  1370.       else
  1371.         {
  1372.           int i;
  1373.           for (i = 0; i < len; i++)
  1374.         ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
  1375.           q += len * UNITS_PER_WORD;
  1376.         }
  1377.     }
  1378.       *q = 0;
  1379.  
  1380.       value = make_node (STRING_CST);
  1381.       TREE_STRING_POINTER (value) = p;
  1382.       TREE_STRING_LENGTH (value) = length;
  1383.       TREE_LITERAL (value) = 1;
  1384.     }
  1385.   else
  1386.     {
  1387.       value = strings;
  1388.       length = TREE_STRING_LENGTH (value);
  1389.       if (TREE_TYPE (value) == int_array_type_node)
  1390.     wide_flag = 1;
  1391.     }
  1392.  
  1393.   /* Create the array type for the string constant.
  1394.      -Wwrite-strings says make the string constant an array of const char
  1395.      so that copying it to a non-const pointer will get a warning.  */
  1396.   if (warn_write_strings)
  1397.     {
  1398.       tree elements
  1399.     = build_type_variant (wide_flag ? integer_type_node : char_type_node,
  1400.                   1, 0);
  1401.       TREE_TYPE (value)
  1402.     = build_array_type (elements,
  1403.                 build_index_type (build_int_2 (length - 1, 0)));
  1404.     }
  1405.   else
  1406.     TREE_TYPE (value)
  1407.       = build_array_type (wide_flag ? integer_type_node : char_type_node,
  1408.               build_index_type (build_int_2 (length - 1, 0)));
  1409.   TREE_LITERAL (value) = 1;
  1410.   TREE_STATIC (value) = 1;
  1411.   return value;
  1412. }
  1413.  
  1414. int lineno;            /* current line number in file being read */
  1415.  
  1416. FILE *finput;            /* input file.
  1417.                    Normally a pipe from the preprocessor.  */
  1418.  
  1419. /* lexical analyzer */
  1420.  
  1421. static int maxtoken;        /* Current nominal length of token buffer.  */
  1422. static char *token_buffer;    /* Pointer to token buffer.
  1423.                    Actual allocated length is maxtoken + 2.  */
  1424. static int max_wide;        /* Current nominal length of wide_buffer.  */
  1425. static int *wide_buffer;    /* Pointer to wide-string buffer.
  1426.                    Actual allocated length is max_wide + 1.  */
  1427.  
  1428. /* Nonzero if end-of-file has been seen on input.  */
  1429. static int end_of_file;
  1430.  
  1431. /* Data type that represents the GNU C reserved words. */
  1432. struct resword { char *name; short token; enum rid rid; };
  1433.  
  1434. #define MIN_WORD_LENGTH     2      /* minimum size for C keyword */
  1435. #define MAX_WORD_LENGTH     13     /* maximum size for C keyword */
  1436. #define MIN_HASH_VALUE      7      /* range of the hash keys values  */
  1437. #define MAX_HASH_VALUE      91     /* for the perfect hash generator */
  1438. #define NORID RID_UNUSED
  1439.  
  1440. /* This function performs the minimum-perfect hash mapping from input
  1441.    string to reswords table index.  It only looks at the first and
  1442.    last characters in the string, thus assuring the O(1) lookup time
  1443.    (this keeps our constant down to an insignificant amount!).  Compiling
  1444.    the following 2 functions as inline removes all overhead of the
  1445.    function calls. */
  1446.  
  1447. #if defined ( __GNUC__ ) && ! defined ( NeXT )
  1448. __inline
  1449. #endif
  1450.  
  1451. static int
  1452. hash (str, len)
  1453.      register char *str;
  1454.      register int len;
  1455. {
  1456. /* This table is used to build the hash table index that recognizes
  1457.    reserved words in 0(1) steps.  It is larger than strictly necessary,
  1458.    but I'm trading off the space for the time-saving luxury of avoiding
  1459.    subtraction of an offset.  All those ``91's'' (actually just a
  1460.    short-hand for MAX_HASH_VALUE #defined above) are used to speed up
  1461.    the search when the string found on the input stream doesn't have a
  1462.    first or last character that is part of the set of alphabetic
  1463.    characters that comprise the first or last characters in C
  1464.    reserved words. */
  1465.  
  1466.   static int hash_table[] =
  1467.     {
  1468.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1469.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1470.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1471.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1472.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1473.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1474.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1475.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1476.      91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
  1477.      91, 91, 91, 91, 91,  1, 91,  2,  1, 32,
  1478.       7,  5, 18, 20,  1, 17, 91,  1, 18,  1,
  1479.      28,  1, 23, 91, 12, 20,  1, 41,  7, 15,
  1480.      91, 91, 10, 91, 91, 91, 91, 91,
  1481.     };
  1482.   register int hval = len ;
  1483.  
  1484.   switch (hval)
  1485.     {
  1486.       default:
  1487.       case 3:
  1488.         hval += hash_table[str[2]];
  1489.       case 2:
  1490.       case 1:
  1491.         return hval + hash_table[str[0]] + hash_table[str[len - 1]];
  1492.     }
  1493. }
  1494.  
  1495. /* This routine attempts to match the string found in the reswords table
  1496.    with the one from the input stream.  If all the relevant details
  1497.    match then an actual strcmp comparison is performed and the address of
  1498.    correct struct resword entry is returned.  Otherwise, a NULL
  1499.    pointer is returned. */
  1500.  
  1501. #if defined ( __GNUC__ ) && ! defined( NeXT )
  1502. __inline
  1503. #endif
  1504. struct resword *
  1505. is_reserved_word (str, len)
  1506.      register char *str;
  1507.      register int len;
  1508. {
  1509.   /* This is the hash table of keywords.
  1510.      The order of keywords has been chosen for perfect hashing.
  1511.      Therefore, this table cannot be updated by hand.
  1512.      Use the program ``gperf,'' available with the latest libg++
  1513.      distribution, to generate an updated table.  A file called
  1514.      c-parse.gperf, distributed with GNU C, contains the keyword file.  */
  1515.  
  1516.   static struct resword reswords[] =
  1517.     {
  1518.       { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, 
  1519.       {"asm",  ASM, NORID },
  1520.       {"auto",  SCSPEC, RID_AUTO },
  1521.       {"__asm",  ASM, NORID },
  1522.       {"do",  DO, NORID },
  1523.       {"__asm__",  ASM, NORID },
  1524.       {"break",  BREAK, NORID },
  1525.       {"__typeof__",  TYPEOF, NORID },
  1526.       { "", }, 
  1527.       {"__alignof__",  ALIGNOF, NORID },
  1528.       { "", }, 
  1529.       {"__attribute__",  ATTRIBUTE, NORID },
  1530.       { "", }, 
  1531.       {"__attribute",  ATTRIBUTE, NORID },
  1532.       { "", }, 
  1533.       {"__volatile__",  TYPE_QUAL, RID_VOLATILE },
  1534.       {"int",  TYPESPEC, RID_INT },
  1535.       {"__volatile",  TYPE_QUAL, RID_VOLATILE },
  1536.       { "", }, 
  1537.       {"float",  TYPESPEC, RID_FLOAT },
  1538.       {"goto",  GOTO, NORID },
  1539.       {"short",  TYPESPEC, RID_SHORT },
  1540.       {"__typeof",  TYPEOF, NORID },
  1541.       {"__inline__",  SCSPEC, RID_INLINE },
  1542.       {"__alignof",  ALIGNOF, NORID },
  1543.       {"__inline",  SCSPEC, RID_INLINE },
  1544.       {"__signed__",  TYPESPEC, RID_SIGNED },
  1545.       {"default",  DEFAULT, NORID },
  1546.       {"else",  ELSE, NORID },
  1547.       {"void",  TYPESPEC, RID_VOID },
  1548.       {"__signed",  TYPESPEC, RID_SIGNED },
  1549.       {"if",  IF, NORID },
  1550.       {"volatile",  TYPE_QUAL, RID_VOLATILE },
  1551.       {"struct",  STRUCT, NORID },
  1552.       {"extern",  SCSPEC, RID_EXTERN },
  1553.       {"__const",  TYPE_QUAL, RID_CONST },
  1554.       {"while",  WHILE, NORID },
  1555.       {"__const__",  TYPE_QUAL, RID_CONST },
  1556.       {"switch",  SWITCH, NORID },
  1557.       {"for",  FOR, NORID },
  1558.       {"inline",  SCSPEC, RID_INLINE },
  1559.       {"return",  RETURN, NORID },
  1560.       {"typeof",  TYPEOF, NORID },
  1561.       {"typedef",  SCSPEC, RID_TYPEDEF },
  1562.       {"char",  TYPESPEC, RID_CHAR },
  1563.       {"enum",  ENUM, NORID },
  1564.       {"register",  SCSPEC, RID_REGISTER },
  1565.       {"signed",  TYPESPEC, RID_SIGNED },
  1566.       {"sizeof",  SIZEOF, NORID },
  1567.       { "", }, { "", }, { "", }, { "", }, 
  1568.       {"double",  TYPESPEC, RID_DOUBLE },
  1569.       {"static",  SCSPEC, RID_STATIC },
  1570.       {"case",  CASE, NORID },
  1571.       { "", }, { "", }, { "", }, { "", }, 
  1572.       {"const",  TYPE_QUAL, RID_CONST },
  1573.       { "", }, { "", }, { "", }, 
  1574.       {"long",  TYPESPEC, RID_LONG },
  1575.       { "", }, { "", }, 
  1576.       {"continue",  CONTINUE, NORID },
  1577.       { "", }, { "", }, 
  1578.       {"unsigned",  TYPESPEC, RID_UNSIGNED },
  1579.       { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, { "", }, 
  1580.       { "", }, { "", }, { "", }, { "", }, { "", }, 
  1581.       {"union",  UNION, NORID },
  1582.     };
  1583.  
  1584.   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
  1585.     {
  1586.       register int key = hash (str, len);
  1587.  
  1588.       if (key <= MAX_HASH_VALUE)
  1589.         {
  1590.           register char *s = reswords[key].name;
  1591.  
  1592.           if (*s == *str && !strcmp (str + 1, s + 1))
  1593.             return &reswords[key];
  1594.         }
  1595.     }
  1596.   return 0;
  1597. }
  1598.  
  1599. /* The elements of `ridpointers' are identifier nodes
  1600.    for the reserved type names and storage classes.
  1601.    It is indexed by a RID_... value.  */
  1602.  
  1603. tree ridpointers[(int) RID_MAX];
  1604.  
  1605. int check_newline ();
  1606.  
  1607. void
  1608. init_lex ()
  1609. {
  1610.   /* Start it at 0, because check_newline is called at the very beginning
  1611.      and will increment it to 1.  */
  1612.   lineno = 0;
  1613.  
  1614.   maxtoken = 40;
  1615.   token_buffer = (char *) xmalloc (maxtoken + 2);
  1616.   max_wide = 40;
  1617.   wide_buffer = (int *) xmalloc (max_wide + 1);
  1618.  
  1619.   ridpointers[(int) RID_INT] = get_identifier ("int");
  1620.   ridpointers[(int) RID_CHAR] = get_identifier ("char");
  1621.   ridpointers[(int) RID_VOID] = get_identifier ("void");
  1622.   ridpointers[(int) RID_FLOAT] = get_identifier ("float");
  1623.   ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
  1624.   ridpointers[(int) RID_SHORT] = get_identifier ("short");
  1625.   ridpointers[(int) RID_LONG] = get_identifier ("long");
  1626.   ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
  1627.   ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
  1628.   ridpointers[(int) RID_INLINE] = get_identifier ("inline");
  1629.   ridpointers[(int) RID_CONST] = get_identifier ("const");
  1630.   ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
  1631.   ridpointers[(int) RID_AUTO] = get_identifier ("auto");
  1632.   ridpointers[(int) RID_STATIC] = get_identifier ("static");
  1633.   ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
  1634.   ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
  1635.   ridpointers[(int) RID_REGISTER] = get_identifier ("register");
  1636. }
  1637.  
  1638. static void
  1639. reinit_parse_for_function ()
  1640. {
  1641. }
  1642.  
  1643. /* If C is not whitespace, return C.
  1644.    Otherwise skip whitespace and return first nonwhite char read.  */
  1645.  
  1646. static int
  1647. skip_white_space (c)
  1648.      register int c;
  1649. {
  1650. #if 0
  1651.   register int inside;
  1652. #endif
  1653.  
  1654.   for (;;)
  1655.     {
  1656.       switch (c)
  1657.     {
  1658.       /* Don't recognize comments in cc1: all comments are removed by cpp,
  1659.          and cpp output can include / and * consecutively as operators.  */
  1660. #if 0
  1661.     case '/':
  1662.       c = getc (finput);
  1663.       if (c != '*')
  1664.         {
  1665.           ungetc (c, finput);
  1666.           return '/';
  1667.         }
  1668.  
  1669.       c = getc (finput);
  1670.  
  1671.       inside = 1;
  1672.       while (inside)
  1673.         {
  1674.           if (c == '*')
  1675.         {
  1676.           while (c == '*')
  1677.             c = getc (finput);
  1678.  
  1679.           if (c == '/')
  1680.             {
  1681.               inside = 0;
  1682.               c = getc (finput);
  1683.             }
  1684.         }
  1685.           else if (c == '\n')
  1686.         {
  1687.           lineno++;
  1688.           c = getc (finput);
  1689.         }
  1690.           else if (c == EOF)
  1691.         {
  1692.           error ("unterminated comment");
  1693.           break;
  1694.         }
  1695.           else
  1696.         c = getc (finput);
  1697.         }
  1698.  
  1699.       break;
  1700. #endif
  1701.  
  1702.     case '\n':
  1703.       c = check_newline ();
  1704.       break;
  1705.  
  1706.     case ' ':
  1707.     case '\t':
  1708.     case '\f':
  1709.     case '\r':
  1710.     case '\v':
  1711.     case '\b':
  1712.       c = getc (finput);
  1713.       break;
  1714.  
  1715.     case '\\':
  1716.       c = getc (finput);
  1717.       if (c == '\n')
  1718.         lineno++;
  1719.       else
  1720.         error ("stray '\\' in program");
  1721.       c = getc (finput);
  1722.       break;
  1723.  
  1724.     default:
  1725.       return (c);
  1726.     }
  1727.     }
  1728. }
  1729.  
  1730.  
  1731.  
  1732. /* Make the token buffer longer, preserving the data in it.
  1733.    P should point to just beyond the last valid character in the old buffer.
  1734.    The value we return is a pointer to the new buffer
  1735.    at a place corresponding to P.  */
  1736.  
  1737. static char *
  1738. extend_token_buffer (p)
  1739.      char *p;
  1740. {
  1741.   int offset = p - token_buffer;
  1742.  
  1743.   maxtoken = maxtoken * 2 + 10;
  1744.   token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
  1745.  
  1746.   return token_buffer + offset;
  1747. }
  1748.  
  1749. /* At the beginning of a line, increment the line number
  1750.    and process any #-directive on this line.
  1751.    If the line is a #-directive, read the entire line and return a newline.
  1752.    Otherwise, return the line's first non-whitespace character.  */
  1753.  
  1754. int
  1755. check_newline ()
  1756. {
  1757.   register int c;
  1758.   register int token;
  1759.  
  1760.   lineno++;
  1761.  
  1762.   /* Read first nonwhite char on the line.  */
  1763.  
  1764.   c = getc (finput);
  1765.   while (c == ' ' || c == '\t')
  1766.     c = getc (finput);
  1767.  
  1768.   if (c != '#')
  1769.     {
  1770.       /* If not #, return it so caller will use it.  */
  1771.       return c;
  1772.     }
  1773.  
  1774.   /* Read first nonwhite char after the `#'.  */
  1775.  
  1776.   c = getc (finput);
  1777.   while (c == ' ' || c == '\t')
  1778.     c = getc (finput);
  1779.  
  1780.   /* If a letter follows, then if the word here is `line', skip
  1781.      it and ignore it; otherwise, ignore the line, with an error
  1782.      if the word isn't `pragma'.  */
  1783.  
  1784.   if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  1785.     {
  1786.       if (c == 'p')
  1787.     {
  1788.       if (getc (finput) == 'r'
  1789.           && getc (finput) == 'a'
  1790.           && getc (finput) == 'g'
  1791.           && getc (finput) == 'm'
  1792.           && getc (finput) == 'a'
  1793.           && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n'))
  1794. #if defined( DSP56000 ) || defined( DSP96000 )
  1795. #if defined( TARGET_PROCESS_PRAGMA_LINE )
  1796.           /* we need pragmas in embedded-processor-ville! */
  1797.           return TARGET_PROCESS_PRAGMA_LINE( finput );
  1798. #else
  1799.         goto skipline;
  1800. #endif
  1801. #else
  1802.         goto skipline;
  1803. #endif
  1804.     }
  1805.  
  1806.       else if (c == 'l')
  1807.     {
  1808.       if (getc (finput) == 'i'
  1809.           && getc (finput) == 'n'
  1810.           && getc (finput) == 'e'
  1811.           && ((c = getc (finput)) == ' ' || c == '\t'))
  1812.         goto linenum;
  1813.     }
  1814.       else if (c == 'i')
  1815.     {
  1816.       if (getc (finput) == 'd'
  1817.           && getc (finput) == 'e'
  1818.           && getc (finput) == 'n'
  1819.           && getc (finput) == 't'
  1820.           && ((c = getc (finput)) == ' ' || c == '\t'))
  1821.         {
  1822.           extern FILE *asm_out_file;
  1823.  
  1824.           if (pedantic)
  1825.         error ("ANSI C does not allow #ident");
  1826.  
  1827.           /* Here we have just seen `#ident '.
  1828.          A string constant should follow.  */
  1829.  
  1830.           while (c == ' ' || c == '\t')
  1831.         c = getc (finput);
  1832.  
  1833.           /* If no argument, ignore the line.  */
  1834.           if (c == '\n')
  1835.         return c;
  1836.  
  1837.           ungetc (c, finput);
  1838.           token = yylex ();
  1839.           if (token != STRING
  1840.           || TREE_CODE (yylval.ttype) != STRING_CST)
  1841.         {
  1842.           error ("invalid #ident");
  1843.           goto skipline;
  1844.         }
  1845.  
  1846. #ifdef ASM_OUTPUT_IDENT
  1847.           ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
  1848. #endif
  1849.  
  1850.           /* Skip the rest of this line.  */
  1851.           goto skipline;
  1852.         }
  1853.     }
  1854.  
  1855.       error ("undefined or invalid # directive");
  1856.       goto skipline;
  1857.     }
  1858.  
  1859. linenum:
  1860.   /* Here we have either `#line' or `# <nonletter>'.
  1861.      In either case, it should be a line number; a digit should follow.  */
  1862.  
  1863.   while (c == ' ' || c == '\t')
  1864.     c = getc (finput);
  1865.  
  1866.   /* If the # is the only nonwhite char on the line,
  1867.      just ignore it.  Check the new newline.  */
  1868.   if (c == '\n')
  1869.     return c;
  1870.  
  1871.   /* Something follows the #; read a token.  */
  1872.  
  1873.   ungetc (c, finput);
  1874.   token = yylex ();
  1875.  
  1876.   if (token == CONSTANT
  1877.       && TREE_CODE (yylval.ttype) == INTEGER_CST)
  1878.     {
  1879.       int old_lineno = lineno;
  1880.       /* subtract one, because it is the following line that
  1881.      gets the specified number */
  1882.  
  1883.       int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
  1884.  
  1885.       /* Is this the last nonwhite stuff on the line?  */
  1886.       c = getc (finput);
  1887.       while (c == ' ' || c == '\t')
  1888.     c = getc (finput);
  1889.       if (c == '\n')
  1890.     {
  1891.       /* No more: store the line number and check following line.  */
  1892.       lineno = l;
  1893.       return c;
  1894.     }
  1895.       ungetc (c, finput);
  1896.  
  1897.       /* More follows: it must be a string constant (filename).  */
  1898.  
  1899.       token = yylex ();
  1900.       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
  1901.     {
  1902.       error ("invalid #line");
  1903.       goto skipline;
  1904.     }
  1905.  
  1906.       input_filename
  1907.     = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
  1908.       strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
  1909.       lineno = l;
  1910.  
  1911.       if (main_input_filename == 0)
  1912.     main_input_filename = input_filename;
  1913.  
  1914.       /* Is this the last nonwhite stuff on the line?  */
  1915.       c = getc (finput);
  1916.       while (c == ' ' || c == '\t')
  1917.     c = getc (finput);
  1918.       if (c == '\n')
  1919.     return c;
  1920.       ungetc (c, finput);
  1921.  
  1922.       token = yylex ();
  1923.  
  1924.       /* `1' after file name means entering new file.
  1925.      `2' after file name means just left a file.  */
  1926.  
  1927.       if (token == CONSTANT
  1928.       && TREE_CODE (yylval.ttype) == INTEGER_CST)
  1929.     {
  1930.       if (TREE_INT_CST_LOW (yylval.ttype) == 1)
  1931.         {
  1932.           struct file_stack *p
  1933.         = (struct file_stack *) xmalloc (sizeof (struct file_stack));
  1934.           input_file_stack->line = old_lineno;
  1935.           p->next = input_file_stack;
  1936.           p->name = input_filename;
  1937.           input_file_stack = p;
  1938.           input_file_stack_tick++;
  1939.         }
  1940.       else if (input_file_stack->next)
  1941.         {
  1942.           struct file_stack *p = input_file_stack;
  1943.           input_file_stack = p->next;
  1944.           free (p);
  1945.           input_file_stack_tick++;
  1946.         }
  1947.       else
  1948.         error ("#-lines for entering and leaving files don't match");
  1949.     }
  1950.     }
  1951.   else
  1952.     error ("invalid #-line");
  1953.  
  1954.   /* skip the rest of this line.  */
  1955.  skipline:
  1956.   if (c == '\n')
  1957.     return c;
  1958.   while ((c = getc (finput)) != EOF && c != '\n');
  1959.   return c;
  1960. }
  1961.  
  1962. #define isalnum(char) ((char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'))
  1963. #define isdigit(char) (char >= '0' && char <= '9')
  1964. #define ENDFILE -1  /* token that represents end-of-file */
  1965.  
  1966.  
  1967. static int
  1968. readescape ()
  1969. {
  1970.   register int c = getc (finput);
  1971.   register int count, code;
  1972.   int firstdig;
  1973.  
  1974.   switch (c)
  1975.     {
  1976.     case 'x':
  1977.       code = 0;
  1978.       count = 0;
  1979.       while (1)
  1980.     {
  1981.       c = getc (finput);
  1982.       if (!(c >= 'a' && c <= 'f')
  1983.           && !(c >= 'A' && c <= 'F')
  1984.           && !(c >= '0' && c <= '9'))
  1985.         {
  1986.           ungetc (c, finput);
  1987.           break;
  1988.         }
  1989.       code *= 16;
  1990.       if (c >= 'a' && c <= 'f')
  1991.         code += c - 'a' + 10;
  1992.       if (c >= 'A' && c <= 'F')
  1993.         code += c - 'A' + 10;
  1994.       if (c >= '0' && c <= '9')
  1995.         code += c - '0';
  1996.       if (count == 0)
  1997.         firstdig = code;
  1998.       count++;
  1999.     }
  2000.       if (count == 0)
  2001.     error ("\\x used with no following hex digits");
  2002. #if ! defined( DSP96000 ) && ! defined( _MSDOS )
  2003.       /* WATCOM C has a problem with shifting '1' 32-bits to the left. */
  2004.       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
  2005.            || ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
  2006.            <= firstdig))
  2007.     warning ("hex escape out of range");
  2008. #endif
  2009.       return code;
  2010.  
  2011.     case '0':  case '1':  case '2':  case '3':  case '4':
  2012.     case '5':  case '6':  case '7':
  2013.       code = 0;
  2014.       count = 0;
  2015.       while ((c <= '7') && (c >= '0') && (count++ < 3))
  2016.     {
  2017.       code = (code * 8) + (c - '0');
  2018.       c = getc (finput);
  2019.     }
  2020.       ungetc (c, finput);
  2021.       return code;
  2022.  
  2023.     case '\\': case '\'': case '"':
  2024.       return c;
  2025.  
  2026.     case '\n':
  2027.       lineno++;
  2028.       return -1;
  2029.  
  2030.     case 'n':
  2031.       return TARGET_NEWLINE;
  2032.  
  2033.     case 't':
  2034.       return TARGET_TAB;
  2035.  
  2036.     case 'r':
  2037.       return TARGET_CR;
  2038.  
  2039.     case 'f':
  2040.       return TARGET_FF;
  2041.  
  2042.     case 'b':
  2043.       return TARGET_BS;
  2044.  
  2045.     case 'a':
  2046.       return TARGET_BELL;
  2047.  
  2048.     case 'v':
  2049.       return TARGET_VT;
  2050.  
  2051.     case 'E':
  2052.       return 033;
  2053.  
  2054.     case '?':
  2055.       /* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
  2056.     case '(':
  2057.     case '{':
  2058.     case '[':
  2059.       return c;
  2060.     }
  2061.   if (c >= 040 && c <= 0177)
  2062.     warning ("unknown escape sequence `\\%c'", c);
  2063.   else
  2064.     warning ("unknown escape sequence: `\\' followed by char code 0x%x", c);
  2065.   return c;
  2066. }
  2067.  
  2068. void
  2069. yyerror (string)
  2070.      char *string;
  2071. {
  2072.   char buf[200];
  2073.  
  2074.   strcpy (buf, string);
  2075.  
  2076.   /* We can't print string and character constants well
  2077.      because the token_buffer contains the result of processing escapes.  */
  2078.   if (end_of_file)
  2079.     strcat (buf, " at end of input");
  2080.   else if (token_buffer[0] == 0)
  2081.     strcat (buf, " at null character");
  2082.   else if (token_buffer[0] == '"')
  2083.     strcat (buf, " before string constant");
  2084.   else if (token_buffer[0] == '\'')
  2085.     strcat (buf, " before character constant");
  2086.   else if (token_buffer[0] < 040 || token_buffer[0] >= 0177)
  2087.     sprintf (buf + strlen (buf), " before character 0%o", token_buffer[0]);
  2088.   else
  2089.     strcat (buf, " before `%s'");
  2090.  
  2091.   error (buf, token_buffer);
  2092. }
  2093.  
  2094. static int nextchar = -1;
  2095.  
  2096. static int
  2097. yylex ()
  2098. {
  2099.   register int c;
  2100.   register char *p;
  2101.   register int value;
  2102.   int wide_flag = 0;
  2103.  
  2104.   if (nextchar >= 0)
  2105.     c = nextchar, nextchar = -1;
  2106.   else
  2107.     c = getc (finput);
  2108.  
  2109.   /* Effectively do c = skip_white_space (c)
  2110.      but do it faster in the usual cases.  */
  2111.   while (1)
  2112.     switch (c)
  2113.       {
  2114.       case ' ':
  2115.       case '\t':
  2116.       case '\f':
  2117.       case '\r':
  2118.       case '\v':
  2119.       case '\b':
  2120.     c = getc (finput);
  2121.     break;
  2122.  
  2123.       case '\n':
  2124.       case '/':
  2125.       case '\\':
  2126.     c = skip_white_space (c);
  2127.       default:
  2128.     goto found_nonwhite;
  2129.       }
  2130.  found_nonwhite:
  2131.  
  2132.   token_buffer[0] = c;
  2133.   token_buffer[1] = 0;
  2134.  
  2135. /*  yylloc.first_line = lineno; */
  2136.  
  2137.   switch (c)
  2138.     {
  2139.     case EOF:
  2140.       end_of_file = 1;
  2141.       token_buffer[0] = 0;
  2142.       value = ENDFILE;
  2143.       break;
  2144.  
  2145.     case '$':
  2146.       if (dollars_in_ident)
  2147.     goto letter;
  2148.       return '$';
  2149.  
  2150.     case 'L':
  2151.       /* Capital L may start a wide-string or wide-character constant.  */
  2152.       {
  2153.     register int c = getc (finput);
  2154.     if (c == '\'')
  2155.       {
  2156.         wide_flag = 1;
  2157.         goto char_constant;
  2158.       }
  2159.     if (c == '"')
  2160.       {
  2161.         wide_flag = 1;
  2162.         goto string_constant;
  2163.       }
  2164.     ungetc (c, finput);
  2165.       }
  2166.  
  2167.     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
  2168.     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
  2169.     case 'K':          case 'M':  case 'N':  case 'O':
  2170.     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
  2171.     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
  2172.     case 'Z':
  2173.     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
  2174.     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
  2175.     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
  2176.     case 'p':  case 'q':  case 'r':  case 's':  case 't':
  2177.     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
  2178.     case 'z':
  2179.     case '_':
  2180.     letter:
  2181.       p = token_buffer;
  2182.       while (isalnum (c) || c == '_' || c == '$')
  2183.     {
  2184.       if (p >= token_buffer + maxtoken)
  2185.         p = extend_token_buffer (p);
  2186.       if (c == '$' && ! dollars_in_ident)
  2187.         break;
  2188.  
  2189.       *p++ = c;
  2190.       c = getc (finput);
  2191.     }
  2192.  
  2193.       *p = 0;
  2194.       nextchar = c;
  2195.  
  2196.       value = IDENTIFIER;
  2197.       yylval.itype = 0;
  2198.  
  2199.       /* Try to recognize a keyword.  Uses minimum-perfect hash function */
  2200.  
  2201.       {
  2202.     register struct resword *ptr;
  2203.  
  2204.     if (ptr = is_reserved_word (token_buffer, p - token_buffer))
  2205.       {
  2206.         if (ptr->rid)
  2207.           yylval.ttype = ridpointers[(int) ptr->rid];
  2208.         if ((! flag_no_asm
  2209.          /* -fno-asm means don't recognize the non-ANSI keywords.  */
  2210.          || ((int) ptr->token != ASM
  2211.              && (int) ptr->token != TYPEOF
  2212.              && ptr->rid != RID_INLINE)
  2213.          /* Recognize __asm and __inline despite -fno-asm.  */
  2214.          || token_buffer[0] == '_')
  2215.         /* -ftraditional means don't recognize nontraditional keywords
  2216.            typeof, const, volatile, signed or inline.  */
  2217.         && (! flag_traditional
  2218.             || ((int) ptr->token != TYPE_QUAL
  2219.             && (int) ptr->token != TYPEOF
  2220.             && ptr->rid != RID_SIGNED
  2221.             && ptr->rid != RID_INLINE)
  2222.             /* Recognize __inline, etc. despite -ftraditional.  */
  2223.             || token_buffer[0] == '_'))
  2224.           value = (int) ptr->token;
  2225.       }
  2226.       }
  2227.  
  2228.       /* If we did not find a keyword, look for an identifier
  2229.      (or a typename).  */
  2230.  
  2231.       if (value == IDENTIFIER)
  2232.     {
  2233.           yylval.ttype = get_identifier (token_buffer);
  2234.       lastiddecl = lookup_name (yylval.ttype);
  2235.  
  2236.       if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL)
  2237.         value = TYPENAME;
  2238.     }
  2239.  
  2240.       break;
  2241.  
  2242.     case '0':  case '1':  case '2':  case '3':  case '4':
  2243.     case '5':  case '6':  case '7':  case '8':  case '9':
  2244.     case '.':
  2245.       {
  2246.     int base = 10;
  2247.     int count = 0;
  2248.     int largest_digit = 0;
  2249.     int numdigits = 0;
  2250.     /* for multi-precision arithmetic,
  2251.        we store only 8 live bits in each short,
  2252.        giving us 64 bits of reliable precision */
  2253.     short shorts[8];
  2254.     int overflow = 0;
  2255.  
  2256.     enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
  2257.       = NOT_FLOAT;
  2258.  
  2259.     for (count = 0; count < 8; count++)
  2260.       shorts[count] = 0;
  2261.  
  2262.     p = token_buffer;
  2263.     *p++ = c;
  2264.  
  2265.     if (c == '0')
  2266.       {
  2267.         *p++ = (c = getc (finput));
  2268.         if ((c == 'x') || (c == 'X'))
  2269.           {
  2270.         base = 16;
  2271.         *p++ = (c = getc (finput));
  2272.           }
  2273.         else
  2274.           {
  2275.         base = 8;
  2276.         numdigits++;
  2277.           }
  2278.       }
  2279.  
  2280.     /* Read all the digits-and-decimal-points.  */
  2281.  
  2282.     while (c == '.'
  2283.            || (isalnum (c) && (c != 'l') && (c != 'L')
  2284.            && (c != 'u') && (c != 'U')
  2285.            && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
  2286.       {
  2287.         if (c == '.')
  2288.           {
  2289.         if (base == 16)
  2290.           error ("floating constant may not be in radix 16");
  2291.         if (floatflag == AFTER_POINT)
  2292.           {
  2293.             error ("malformed floating constant");
  2294.             floatflag = TOO_MANY_POINTS;
  2295.           }
  2296.         else
  2297.           floatflag = AFTER_POINT;
  2298.  
  2299.         base = 10;
  2300.         *p++ = c = getc (finput);
  2301.         /* Accept '.' as the start of a floating-point number
  2302.            only when it is followed by a digit.
  2303.            Otherwise, unread the following non-digit
  2304.            and use the '.' as a structural token.  */
  2305.         if (p == token_buffer + 2 && !isdigit (c))
  2306.           {
  2307.             if (c == '.')
  2308.               {
  2309.             c = getc (finput);
  2310.             if (c == '.')
  2311.               {
  2312.                 *p++ = c;
  2313.                 *p = 0;
  2314.                 return ELLIPSIS;
  2315.               }
  2316.             error ("parse error at `..'");
  2317.               }
  2318.             ungetc (c, finput);
  2319.             token_buffer[1] = 0;
  2320.             value = '.';
  2321.             goto done;
  2322.           }
  2323.           }
  2324.         else
  2325.           {
  2326.         /* It is not a decimal point.
  2327.            It should be a digit (perhaps a hex digit).  */
  2328.  
  2329.         if (isdigit (c))
  2330.           {
  2331.             c = c - '0';
  2332.           }
  2333.         else if (base <= 10)
  2334.           {
  2335.             if ((c&~040) == 'E')
  2336.               {
  2337.             base = 10;
  2338.             floatflag = AFTER_POINT;
  2339.             break;   /* start of exponent */
  2340.               }
  2341.             error ("nondigits in number and not hexadecimal");
  2342.             c = 0;
  2343.           }
  2344.         else if (c >= 'a')
  2345.           {
  2346.             c = c - 'a' + 10;
  2347.           }
  2348.         else
  2349.           {
  2350.             c = c - 'A' + 10;
  2351.           }
  2352.         if (c >= largest_digit)
  2353.           largest_digit = c;
  2354.         numdigits++;
  2355.  
  2356.         for (count = 0; count < 8; count++)
  2357.           {
  2358.             shorts[count] *= base;
  2359.             if (count)
  2360.               {
  2361.             shorts[count] += (shorts[count-1] >> 8);
  2362.             shorts[count-1] &= (1<<8)-1;
  2363.               }
  2364.             else shorts[0] += c;
  2365.           }
  2366.  
  2367.         if (shorts[7] >= 1<<8
  2368.             || shorts[7] < - (1 << 8))
  2369.           overflow = TRUE;
  2370.  
  2371.         if (p >= token_buffer + maxtoken - 3)
  2372.           p = extend_token_buffer (p);
  2373.         *p++ = (c = getc (finput));
  2374.           }
  2375.       }
  2376.  
  2377.     if (numdigits == 0)
  2378.       error ("numeric constant with no digits");
  2379.  
  2380.     if (largest_digit >= base)
  2381.       error ("numeric constant contains digits beyond the radix");
  2382.  
  2383.     /* Remove terminating char from the token buffer and delimit the string */
  2384.     *--p = 0;
  2385.  
  2386.     if (floatflag != NOT_FLOAT)
  2387.       {
  2388.         tree type = double_type_node;
  2389.         char f_seen = 0;
  2390.         char l_seen = 0;
  2391.         REAL_VALUE_TYPE value;
  2392.  
  2393.         /* Read explicit exponent if any, and put it in tokenbuf.  */
  2394.  
  2395.         if ((c == 'e') || (c == 'E'))
  2396.           {
  2397.         if (p >= token_buffer + maxtoken - 3)
  2398.           p = extend_token_buffer (p);
  2399.         *p++ = c;
  2400.         c = getc (finput);
  2401.         if ((c == '+') || (c == '-'))
  2402.           {
  2403.             *p++ = c;
  2404.             c = getc (finput);
  2405.           }
  2406.         if (! isdigit (c))
  2407.           error ("floating constant exponent has no digits");
  2408.             while (isdigit (c))
  2409.           {
  2410.             if (p >= token_buffer + maxtoken - 3)
  2411.               p = extend_token_buffer (p);
  2412.             *p++ = c;
  2413.             c = getc (finput);
  2414.           }
  2415.           }
  2416.  
  2417.         *p = 0;
  2418.         errno = 0;
  2419.         value = REAL_VALUE_ATOF (token_buffer);
  2420. #ifdef ERANGE
  2421.         if (errno == ERANGE && !flag_traditional)
  2422.           {
  2423.         char *p1 = token_buffer;
  2424.         /* Check for "0.0" and variants;
  2425.            Sunos 4 spuriously returns ERANGE for them.  */
  2426.         while (*p1 == '0') p1++;
  2427.         if (*p1 == '.')
  2428.           {
  2429.             p1++;
  2430.             while (*p1 == '0') p1++;
  2431.           }
  2432.         if (*p1 == 'e' || *p1 == 'E')
  2433.           {
  2434.             /* with significand==0, ignore the exponent */
  2435.             p1++;
  2436.             while (*p1 != 0) p1++;
  2437.           }
  2438.         /* ERANGE is also reported for underflow,
  2439.            so test the value to distinguish overflow from that.  */
  2440.         if (*p1 != 0 && (value > 1.0 || value < 1.0))
  2441.           warning ("floating point number exceeds range of `double'");
  2442.           }
  2443. #endif
  2444.  
  2445.         /* Read the suffixes to choose a data type.  */
  2446.         while (1)
  2447.           {
  2448.         if (c == 'f' || c == 'F')
  2449.           {
  2450.             float floater;
  2451.             if (f_seen)
  2452.               error ("two `f's in floating constant");
  2453.             f_seen = 1;
  2454.             type = float_type_node;
  2455.             floater = value;
  2456.             value = floater;
  2457.           }
  2458.         else if (c == 'l' || c == 'L')
  2459.           {
  2460.             if (l_seen)
  2461.               error ("two `l's in floating constant");
  2462.             l_seen = 1;
  2463.             type = long_double_type_node;
  2464.           }
  2465.         else
  2466.           {
  2467.             if (isalnum (c))
  2468.               {
  2469.             error ("garbage at end of number");
  2470.             while (isalnum (c))
  2471.               {
  2472.                 if (p >= token_buffer + maxtoken - 3)
  2473.                   p = extend_token_buffer (p);
  2474.                 *p++ = c;
  2475.                 c = getc (finput);
  2476.               }
  2477.               }
  2478.             break;
  2479.           }
  2480.         if (p >= token_buffer + maxtoken - 3)
  2481.           p = extend_token_buffer (p);
  2482.         *p++ = c;
  2483.         c = getc (finput);
  2484.           }
  2485.  
  2486.         /* Create a node with determined type and value.  */
  2487.         yylval.ttype = build_real (type, value);
  2488.  
  2489.         ungetc (c, finput);
  2490.         *p = 0;
  2491.       }
  2492.     else
  2493.       {
  2494.         tree type;
  2495.         int spec_unsigned = 0;
  2496.         int spec_long = 0;
  2497.         int spec_long_long = 0;
  2498.  
  2499.         while (1)
  2500.           {
  2501.         if (c == 'u' || c == 'U')
  2502.           {
  2503.             if (spec_unsigned)
  2504.               error ("two `u's in integer constant");
  2505.             spec_unsigned = 1;
  2506.           }
  2507.         else if (c == 'l' || c == 'L')
  2508.           {
  2509.             if (spec_long)
  2510.               {
  2511.             if (spec_long_long)
  2512.               error ("three `l's in integer constant");
  2513.             else if (pedantic)
  2514.               warning ("ANSI C forbids long long integer constants");
  2515.             spec_long_long = 1;
  2516.               }
  2517.             spec_long = 1;
  2518.           }
  2519.         else
  2520.           {
  2521.             if (isalnum (c))
  2522.               {
  2523.             error ("garbage at end of number");
  2524.             while (isalnum (c))
  2525.               {
  2526.                 if (p >= token_buffer + maxtoken - 3)
  2527.                   p = extend_token_buffer (p);
  2528.                 *p++ = c;
  2529.                 c = getc (finput);
  2530.               }
  2531.               }
  2532.             break;
  2533.           }
  2534.         if (p >= token_buffer + maxtoken - 3)
  2535.           p = extend_token_buffer (p);
  2536.         *p++ = c;
  2537.         c = getc (finput);
  2538.           }
  2539.  
  2540.         ungetc (c, finput);
  2541.  
  2542. #if defined( DSP56000 )
  2543.         if (overflow)
  2544. #else
  2545.         if ((overflow || shorts[7] || shorts[6] || shorts[5] || shorts[4])
  2546.         && !spec_long_long)
  2547. #endif
  2548.           warning ("integer constant out of range");
  2549.  
  2550.         /* If it won't fit in a signed long long, make it unsigned.
  2551.            We can't distinguish based on the tree node because
  2552.            any integer constant fits any long long type.  */
  2553.         if (shorts[7] >= (1<<8))
  2554.           spec_unsigned = 1;
  2555.  
  2556.         /* This is simplified by the fact that our constant
  2557.            is always positive.  */
  2558.         yylval.ttype
  2559.           = (build_int_2
  2560.          ((shorts[3]<<24) + (shorts[2]<<16) + (shorts[1]<<8) + shorts[0],
  2561. #if defined( DSP56000 )
  2562.           (shorts[7]<<24) + (shorts[6]<<16) + (shorts[5]<<8) + shorts[4]));
  2563. #else
  2564.         (spec_long_long
  2565.            ? ((shorts[7]<<24) + (shorts[6]<<16) + (shorts[5]<<8) + shorts[4]) : 0)));
  2566. #endif
  2567.  
  2568.         if (!spec_long && !spec_unsigned
  2569.         && int_fits_type_p (yylval.ttype, integer_type_node))
  2570.           type = integer_type_node;
  2571.  
  2572. #if defined( DSP56000 )
  2573.         else if (!spec_long && ( base != 10 || spec_unsigned )
  2574. #else
  2575.         else if (!spec_long && base != 10
  2576. #endif
  2577.              && int_fits_type_p (yylval.ttype, unsigned_type_node))
  2578.           type = unsigned_type_node;
  2579.  
  2580.         else if (!spec_unsigned && !spec_long_long
  2581.              && int_fits_type_p (yylval.ttype, long_integer_type_node))
  2582.           type = long_integer_type_node;
  2583.  
  2584.         else if (! spec_long_long
  2585.              && int_fits_type_p (yylval.ttype,
  2586.                      long_unsigned_type_node))
  2587.           type = long_unsigned_type_node;
  2588.  
  2589.         else if (! spec_unsigned
  2590.              && int_fits_type_p (yylval.ttype,
  2591.                      long_long_integer_type_node))
  2592.           type = long_long_integer_type_node;
  2593.  
  2594.         else if (int_fits_type_p (yylval.ttype,
  2595.                       long_long_unsigned_type_node))
  2596.           type = long_long_unsigned_type_node;
  2597.  
  2598.         else
  2599.           {
  2600.         type = long_long_integer_type_node;
  2601.         warning ("integer constant out of range");
  2602.           }
  2603.  
  2604.         TREE_TYPE (yylval.ttype) = type;
  2605.       }
  2606.  
  2607.     value = CONSTANT; break;
  2608.       }
  2609.  
  2610.     case '\'':
  2611.     char_constant:
  2612.       {
  2613.     register int result = 0;
  2614.     register num_chars = 0;
  2615.     int width = TYPE_PRECISION (char_type_node);
  2616.     int max_chars;
  2617.  
  2618. #if defined( DSP56000 ) || defined( DSP96000 )
  2619.     width = 8;
  2620.     max_chars = TYPE_PRECISION (integer_type_node) / width;
  2621. #else
  2622.     if (wide_flag) width = TYPE_PRECISION (integer_type_node);
  2623.     max_chars = TYPE_PRECISION (integer_type_node) / width;
  2624. #endif
  2625.  
  2626.     while (1)
  2627.       {
  2628.       tryagain:
  2629.  
  2630.         c = getc (finput);
  2631.  
  2632.         if (c == '\'' || c == EOF)
  2633.           break;
  2634.  
  2635.         if (c == '\\')
  2636.           {
  2637.         c = readescape ();
  2638.         if (c < 0)
  2639.           goto tryagain;
  2640. #if ! defined( DSP96000 )
  2641.         if (width < HOST_BITS_PER_INT
  2642.             && (unsigned) c >= (1 << width))
  2643.           warning ("escape sequence out of range for character");
  2644. #endif
  2645.           }
  2646.         else if (c == '\n')
  2647.           {
  2648.         if (pedantic)
  2649.           warning ("ANSI C forbids newline in character constant");
  2650.         lineno++;
  2651.           }
  2652.  
  2653.         num_chars++;
  2654.         if (num_chars > maxtoken - 4)
  2655.           extend_token_buffer (token_buffer);
  2656.  
  2657.         token_buffer[num_chars] = c;
  2658.  
  2659.         /* Merge character into result; ignore excess chars.  */
  2660.         if (num_chars < max_chars + 1)
  2661.           {
  2662.         if (width < HOST_BITS_PER_INT)
  2663.           result = (result << width) | (c & ((1 << width) - 1));
  2664.         else
  2665.           result = c;
  2666.           }
  2667.       }
  2668.  
  2669.     token_buffer[num_chars + 1] = '\'';
  2670.     token_buffer[num_chars + 2] = 0;
  2671.  
  2672.     if (c != '\'')
  2673.       error ("malformatted character constant");
  2674.     else if (num_chars == 0)
  2675.       error ("empty character constant");
  2676.     else if (num_chars > max_chars)
  2677.       {
  2678.         num_chars = max_chars;
  2679.         error ("character constant too long");
  2680.       }
  2681. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  2682.     else if (num_chars != 1 && ! flag_traditional)
  2683.       warning ("multi-character character constant");
  2684. #endif
  2685.  
  2686.     /* If char type is signed, sign-extend the constant.  */
  2687.     if (! wide_flag)
  2688.       {
  2689.         int num_bits = num_chars * width;
  2690.         if (TREE_UNSIGNED (char_type_node)
  2691.         || ((result >> (num_bits - 1)) & 1) == 0)
  2692.           yylval.ttype
  2693.         = build_int_2 (result & ((unsigned) ~0
  2694.                      >> (HOST_BITS_PER_INT - num_bits)),
  2695.                    0);
  2696.         else
  2697.           yylval.ttype
  2698.         = build_int_2 (result | ~((unsigned) ~0
  2699.                       >> (HOST_BITS_PER_INT - num_bits)),
  2700.                    -1);
  2701.       }
  2702.     else
  2703.       yylval.ttype = build_int_2 (result, 0);
  2704.  
  2705.     TREE_TYPE (yylval.ttype) = integer_type_node;
  2706.     value = CONSTANT; break;
  2707.       }
  2708.  
  2709.     case '"':
  2710.     string_constant:
  2711.       {
  2712.     int *widep;
  2713.  
  2714.     c = getc (finput);
  2715.     p = token_buffer + 1;
  2716.  
  2717.     if (wide_flag)
  2718.       widep = wide_buffer;
  2719.  
  2720.     while (c != '"' && c >= 0)
  2721.       {
  2722.         if (c == '\\')
  2723.           {
  2724.         c = readescape ();
  2725.         if (c < 0)
  2726.           goto skipnewline;
  2727. #if defined( DSP96000 )
  2728.         /* this won't work because chars are 32 bits on the 96k. */
  2729. #else
  2730.         if (!wide_flag && c >= (1 << TYPE_PRECISION (char_type_node)))
  2731.           warning ("escape sequence out of range for character");
  2732. #endif
  2733.           }
  2734.         else if (c == '\n')
  2735.           {
  2736.         if (pedantic)
  2737.           warning ("ANSI C forbids newline in string constant");
  2738.         lineno++;
  2739.           }
  2740.  
  2741.         /* Store the char in C into the appropriate buffer.  */
  2742.  
  2743. #if defined( DSP56000 ) || defined( DSP96000 )
  2744.         /* we take the following approach: import the char string as
  2745.            usual, then run a compiler resident copy of the target
  2746.            mbstowcs function to create the wide string. */
  2747. #else
  2748.         if (wide_flag)
  2749.           {
  2750.         if (widep == wide_buffer + max_wide)
  2751.           {
  2752.             int n = widep - wide_buffer;
  2753.             max_wide *= 2;
  2754.             wide_buffer = (int *) xrealloc (wide_buffer, max_wide + 1);
  2755.             widep = wide_buffer + n;
  2756.           }
  2757.         *widep++ = c;
  2758.           }
  2759.         else
  2760. #endif
  2761.           {
  2762.         if (p == token_buffer + maxtoken)
  2763.           p = extend_token_buffer (p);
  2764.         *p++ = c;
  2765.           }
  2766.  
  2767.       skipnewline:
  2768.         c = getc (finput);
  2769.       }
  2770.  
  2771.     /* We have read the entire constant.
  2772.        Construct a STRING_CST for the result.  */
  2773.  
  2774.     if (wide_flag)
  2775.       {
  2776.         /* If this is a L"..." wide-string, make a vector
  2777.            of the ints in wide_buffer.  */
  2778.         *widep = 0;
  2779.         /* We have not implemented the case where `int'
  2780.            on the target and on the execution machine differ in size.  */
  2781. #if defined( DSP56000 ) || defined( DSP96000 )
  2782.         /* The above comment does not hold for the 56k or 96k. */
  2783.  
  2784.         {
  2785.         int wchars = ( p - token_buffer ) + 1; /* overkill, I know. */
  2786.         
  2787.         *p = '\0'; /* terminate the string. */
  2788.         
  2789.         if ( wchars > max_wide )
  2790.         {
  2791.             max_wide *= 2;
  2792.             wide_buffer = (int *) xrealloc (wide_buffer, max_wide + 1);
  2793.         }
  2794.         
  2795.         wchars = target_mbstowcs ( wide_buffer, token_buffer + 1 );
  2796.         
  2797.         if ( -1 == wchars )
  2798.         {
  2799.             error ("invalid wide char string");
  2800.         }
  2801.         widep = wide_buffer + wchars;
  2802.         }
  2803. #else
  2804.         if (TYPE_PRECISION (integer_type_node)
  2805.         != sizeof (int) * BITS_PER_UNIT)
  2806.           abort ();
  2807. #endif
  2808.         yylval.ttype
  2809.           = build_string ((widep - wide_buffer + 1) * sizeof (int),
  2810.                   wide_buffer);
  2811.         TREE_TYPE (yylval.ttype) = int_array_type_node;
  2812.       }
  2813.     else
  2814.       {
  2815.         *p = 0;
  2816.         yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
  2817.         TREE_TYPE (yylval.ttype) = char_array_type_node;
  2818.       }
  2819.  
  2820.     *p++ = '"';
  2821.     *p = 0;
  2822.  
  2823.     value = STRING; break;
  2824.       }
  2825.  
  2826.     case '+':
  2827.     case '-':
  2828.     case '&':
  2829.     case '|':
  2830.     case '<':
  2831.     case '>':
  2832.     case '*':
  2833.     case '/':
  2834.     case '%':
  2835.     case '^':
  2836.     case '!':
  2837.     case '=':
  2838.       {
  2839.     register int c1;
  2840.  
  2841.       combine:
  2842.  
  2843.     switch (c)
  2844.       {
  2845.       case '+':
  2846.         yylval.code = PLUS_EXPR; break;
  2847.       case '-':
  2848.         yylval.code = MINUS_EXPR; break;
  2849.       case '&':
  2850.         yylval.code = BIT_AND_EXPR; break;
  2851.       case '|':
  2852.         yylval.code = BIT_IOR_EXPR; break;
  2853.       case '*':
  2854.         yylval.code = MULT_EXPR; break;
  2855.       case '/':
  2856.         yylval.code = TRUNC_DIV_EXPR; break;
  2857.       case '%':
  2858.         yylval.code = TRUNC_MOD_EXPR; break;
  2859.       case '^':
  2860.         yylval.code = BIT_XOR_EXPR; break;
  2861.       case LSHIFT:
  2862.         yylval.code = LSHIFT_EXPR; break;
  2863.       case RSHIFT:
  2864.         yylval.code = RSHIFT_EXPR; break;
  2865.       case '<':
  2866.         yylval.code = LT_EXPR; break;
  2867.       case '>':
  2868.         yylval.code = GT_EXPR; break;
  2869.       }
  2870.  
  2871.     token_buffer[1] = c1 = getc (finput);
  2872.     token_buffer[2] = 0;
  2873.  
  2874.     if (c1 == '=')
  2875.       {
  2876.         switch (c)
  2877.           {
  2878.           case '<':
  2879.         value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
  2880.           case '>':
  2881.         value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
  2882.           case '!':
  2883.         value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
  2884.           case '=':
  2885.         value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
  2886.           }
  2887.         value = ASSIGN; goto done;
  2888.       }
  2889.     else if (c == c1)
  2890.       switch (c)
  2891.         {
  2892.         case '+':
  2893.           value = PLUSPLUS; goto done;
  2894.         case '-':
  2895.           value = MINUSMINUS; goto done;
  2896.         case '&':
  2897.           value = ANDAND; goto done;
  2898.         case '|':
  2899.           value = OROR; goto done;
  2900.         case '<':
  2901.           c = LSHIFT;
  2902.           goto combine;
  2903.         case '>':
  2904.           c = RSHIFT;
  2905.           goto combine;
  2906.         }
  2907.     else if ((c == '-') && (c1 == '>'))
  2908.       { value = POINTSAT; goto done; }
  2909.     ungetc (c1, finput);
  2910.     token_buffer[1] = 0;
  2911.  
  2912.     if ((c == '<') || (c == '>'))
  2913.       value = ARITHCOMPARE;
  2914.     else value = c;
  2915.     goto done;
  2916.       }
  2917.  
  2918.     case 0:
  2919.       /* Don't make yyparse think this is eof.  */
  2920.       value = 1;
  2921.       break;
  2922.  
  2923.     default:
  2924.       value = c;
  2925.     }
  2926.  
  2927. done:
  2928. /*  yylloc.last_line = lineno; */
  2929.  
  2930.   return value;
  2931. }
  2932.